TranscryptOrg / Transcrypt

Python 3.9 to JavaScript compiler - Lean, fast, open!
https://www.transcrypt.org
Apache License 2.0
2.85k stars 214 forks source link

Transcrypt not able to translate addict.py correctly : Creates circular dependency #823

Open sandeep-gh opened 2 years ago

sandeep-gh commented 2 years ago

Transcrypt runs without error and produces output when ran over addict.py (a library on top of Dict, that uses some python dunder function hooks to make dictionary operations via class/object access patterns). I am using this https://github.com/sandeep-gh/addict fork.

Transcrypt compiles addict and reports no error. However, the generated javascript has no code corresponding to addict functions and it seems to have created a recursive definition which breaks rollup bundler (see Circular Dependency) Attached below is the relevant snippet of the generate addict.js.

'use strict';
import {
...
...
...
} from "./org.transcrypt.__runtime__.js";
import {
    Dict as Addict
} from "./addict.js";
import {
    Dict,
    walker
} from "./addict.js";
export {
    walker,
    Dict,
    Addict
};
....

The import line seems to be creating a circular dependency since within addict.js we are saying import Dict from addict.js. Are libraries like addict.py not transcryptable? Any high level idea how to debug/fix would be great.

JennaSys commented 1 month ago

I created a module to test this and to get around some namespace confusion, I changed the import in my test from

from addict import Dict

to

from addict.addict import Dict

and bypassed the addict/__init__.py module. And while this got around one problem, Transcrypt wouldn't process the library anyway:

$ transcrypt --nomin --verbose addict_test.py

Error while compiling (offending file last):
    File 'addict_test.py', line 1, at import of:
    File 'addict.addict', line 35, namely:

    Built in function 'super' with arguments not supported

Aborted

It appears that the addict library has a few lines of Python code that Transcrypt is unable to process in its current form.