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
Inaccurate code is generated for a relative import statement inside an __init__.py module of a nested package (usually leading to an ImportError at program runtime).
Conditions:
Relative import statement
Module is the __init__.py module
The package / directory of the __init__.py is not the top-level one (file not the highest __init__.py)
Outcome:
The statement tries to import from the parent package of the correct package, generally causing an ImportError.
E.g. (typed) from .module import foo -> (compiled) from ..module import foo
To reproduce:
Have mypy 1.12.0, and its mypyc extension, installed.
Create a file structure as follows:
In a/b/__init__.py, add a valid relative import statement:
from . importbar
Compile with mypyc a in the terminal, successfully.
Execute the following statement to run a/b/__init__.py, in the python IDLE or a new ./main.py file:
importa.b
Result:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "a\b\__init__.py", line 1, in <module>
from . import bar
ImportError: cannot import name 'bar' from 'a' (~\mypyc-test\a\__init__.cp312-win_amd64.pyd)
The statement tries to import a.bar instead of the intended a.b.bar
Expected behavior
The compiled program runs with no errors, the relative import statement is generated correctly.
Actual behavior
The generated relative import is off by one level, often causing an import error when running the compiled program.
Environment
Mypy version used: 1.12.0 (compiled)
Mypy command-line flags: none
Mypy configuration options from mypy.ini (and other config files): none
Python version used: 3.12.4
Windows 11
The text was updated successfully, but these errors were encountered:
Inaccurate code is generated for a relative import statement inside an
__init__.py
module of a nested package (usually leading to anImportError
at program runtime).Conditions:
__init__.py
module__init__.py
is not the top-level one (file not the highest__init__.py
)Outcome:
The statement tries to import from the parent package of the correct package, generally causing an
ImportError
.E.g. (typed)
from .module import foo
-> (compiled)from ..module import foo
To reproduce:
Have mypy 1.12.0, and its mypyc extension, installed.
Create a file structure as follows:
In
a/b/__init__.py
, add a valid relative import statement:Compile with
mypyc a
in the terminal, successfully.Execute the following statement to run
a/b/__init__.py
, in the python IDLE or a new./main.py
file:Result:
The statement tries to import
a.bar
instead of the intendeda.b.bar
Expected behavior
The compiled program runs with no errors, the relative import statement is generated correctly.
Actual behavior
The generated relative import is off by one level, often causing an import error when running the compiled program.
Environment
The text was updated successfully, but these errors were encountered: