Skip to content

Fixed many python compatiblity issues - #900

Open
kochelmonster wants to merge 31 commits into
TranscryptOrg:masterfrom
kochelmonster:master
Open

Fixed many python compatiblity issues#900
kochelmonster wants to merge 31 commits into
TranscryptOrg:masterfrom
kochelmonster:master

Conversation

@kochelmonster

Copy link
Copy Markdown
  • relative import
  • metaclass
  • descriptor protocol
  • id, frozenset, getattr
  • missing modules
  • type and super

kochelmonster and others added 30 commits December 6, 2021 18:57
+ string.lstrip, string.rstrip with arguments.
@JennaSys

Copy link
Copy Markdown
Collaborator

Thank you for the contribution. There is a lot in here that I'll have to dig through. TBH, I'll likely end up having to cherry pick some of the updates rather than do one massive merge. But, at least based on the commit messages, I'm looking forward to adding some of these features.

Also just so you know, I'm currently in the process of updating the Transcrypt compiler to be compatible with Python 3.13 and any new features will need to be added after that is released.

def count_100(index):
    for j in range(100):
        index = index + 1
    return index

Generated wrong to:

export var count_100 = function (index) {
	for (var j = 0; j < 100; j++) {
		var index = index + 1;  // var is wrong
	}
	return index;
};

------

def count_101(index):
    idx = index
    for j in range(101):
        idx = idx + 1
    return idx

Generated wrong to:

export var count_101 = function (index) {
	var idx = index;
	for (var j = 0; j < 101; j++) {
		var idx = idx + 1;   // var is wrong
	}
	return idx;
};

@codeCraft-Ritik codeCraft-Ritik left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a clean fix — nice catch on the root cause. The var re-emission
bug wasn't really about loops specifically, it was that the scope object
had no memory of "this name is already a local," so every assignment
re-triggered the declaration branch. Tracking that explicitly via
scope.locals_ (and seeding it with the function's own parameters in
emitScopedBody) is the right fix rather than special-casing loops or
adding a first-assignment check inline.

The two repro cases in the commit message make this easy to verify too —
appreciate you including the actual generated JS output for both, that's
usually the missing piece in compiler bug reports. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants