You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The standard library for Python contains importlib, which contains a pure* Python implementation of the import machinery. This is lucky as we then don't have to implement it all in Rust. But we have to bootstrap it and implement all of the functionality it uses from builtin modules.
level and globals argument is not provided and relative import is not working.
As example import unittest is broken at:
from .resultimportTestResult
Example:
module/__init__.py:
from .secondimportvalue
module/second.py:
value=1
Expected result
python -c 'import module; print(module.value)'
1
Current result
cargo run -- -c 'import module; print(module.value)'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "None", line 1093, in __import__
File "None", line 1014, in _gcd_import
File "None", line 991, in _find_and_load
File "None", line 975, in _find_and_load_unlocked
File "None", line 686, in _load_unlocked
File "None", line 677, in _load_unlocked
File "None", line 671, in _load_unlocked
File "None", line 778, in exec_module
File "None", line 219, in _call_with_frames_removed
File ".../RustPython/module/__init__.py", line 1, in <module>
from .second import value
File "None", line 1093, in __import__
File "None", line 1014, in _gcd_import
File "None", line 991, in _find_and_load
File "None", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named '.second'
@apatrushev please look at the implementation of the relative import at #1050.
I took a short look on the code in PR. Unfortunately I have no strong opinion on where to place this code in compile or in vm execution because I am not confident neither in CPython code nor in RustPython. And I have no idea why CPython doing this in compile time - I just put my investigations here for the history to save the time later.
Besides this disclaimer your code LGTM (and import unittest moved forward!).
Activity
palaviv commentedon Jun 5, 2019
An initial implementation can be found in #1018.
palaviv commentedon Jun 7, 2019
Another thing that would help this is supporting
{!r}in string format.palaviv commentedon Jun 18, 2019
This can be closed not that #1018 was merged
apatrushev commentedon Jun 18, 2019
UPD: Related to #55
levelandglobalsargument is not provided and relative import is not working.As example
import unittestis broken at:Example:
module/__init__.py:module/second.py:Expected result
python -c 'import module; print(module.value)'Current result
cargo run -- -c 'import module; print(module.value)'apatrushev commentedon Jun 21, 2019
Additional investigation - CPython does level magic in compile:
python -c "import dis; dis.dis(compile('from .second import value', '', 'exec'))"(note second dot)
python -c "import dis; dis.dis(compile('from ..second import value', '', 'exec'))"palaviv commentedon Jun 21, 2019
@apatrushev please look at the implementation of the relative import at #1050.
apatrushev commentedon Jun 21, 2019
I took a short look on the code in PR. Unfortunately I have no strong opinion on where to place this code in compile or in vm execution because I am not confident neither in CPython code nor in RustPython. And I have no idea why CPython doing this in compile time - I just put my investigations here for the history to save the time later.
Besides this disclaimer your code LGTM (and
import unittestmoved forward!).palaviv commentedon Jun 30, 2019
@Skinny121, @apatrushev can we close this issue?