grumpyhome / grumpy

Grumpy is a Python to Go source code transcompiler and runtime.
Apache License 2.0
420 stars 18 forks source link

Fix circular imports (zipfile.py) #128

Closed alanjds closed 5 years ago

alanjds commented 5 years ago

On Python the circular imports are usually handled by issuing it inside the function needing it.

module_A.function_one needs module_B.function_one, but module_B.method_two can need module_A.helper_two, that is evaluated on run time. This makes the A -> B -> A work by letting the B -> be lazy.

However Go does not allow it. The solution was to bubble up all the imports to the main.go, as it was before the PEP-3147 (__pycache__) support got added.

This is needed, e.g., by zipfile.py that imports shutil.py that conditionally imports zipfile.py