Fixed many python compatiblity issues - #900
Conversation
kochelmonster
commented
Jun 22, 2025
- relative import
- metaclass
- descriptor protocol
- id, frozenset, getattr
- missing modules
- type and super
…with 3 arguments.
+ string.lstrip, string.rstrip with arguments.
…ltiple arguments.
…ing. Improved __super__.
|
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
left a comment
There was a problem hiding this comment.
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. 👍