TranscryptOrg / Transcrypt

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

"from typing import X" leads to a run-time error in 3.7.4 #555

Open wrpscott opened 6 years ago

wrpscott commented 6 years ago

This is to report a difference in behaviour of 3.7 compared to 3.6 versions of transcrypt.

An import statement of the form 'from typing import Tuple' in python leads, unsurprisingly, to the following line in the produced javascript code: import {Tuple} from './typing.js'; This, however, fails at javascript run-time, as Tuple is not actually exported from typing.js. Note that functions from typing are never actually called, and commenting out the line in the javascript file leads to successful execution of the code. NOTE: an easy workaround is to use 'import typing' in the python code instead. This leads, among other lines, to the following javascript code: import * as __module_typing__ from './typing.js'; which is sufficiently nonspecific to pass at run-time. An alternative solution for transcrypt would be to treat the typing module as a special case and not import it at all in the javascript code.

BLeAm commented 6 years ago

For now I use 'from typing import *' as a workaround, maybe # __:skip at the end of the typing import line works as well.

JdeH commented 6 years ago

Will take a closer look...

Zireael07 commented 4 years ago

Just ran into this myself.