-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failure to resolve a specific import structure #4144
Comments
What does |
[["n0", 91875, ["_importlib_modulespec", "mypy_extensions", "types", "abc", "typing", "builtins", "collections", "sys", "collections.abc"],
{"_importlib_modulespec": 1810, "mypy_extensions": 731, "types": 7066, "abc": 809, "typing": 18315, "builtins": 43416, "collections": 13579, "sys": 5019, "collections.abc": 1130},
{}],
["n1", 120, ["top.b._b", "top.c", "top.b", "top"],
{"top.b._b": 33, "top.c": 35, "top.b": 18, "top": 34},
{}]
] |
So from that I learn it's an import cycle problem, where c is processed
before b. A workaround may be to change c to say "from b import Cls".
|
Yes, that workaround would work in this case. That said, python itself has no problem with cycles like this. You can import a module which is currently being loaded, you're just not guaranteed that it'll have all the attributes you want. More specifically, an import of |
Mypy sometimes gets this right too, but not in all cases, because it does
not emulate the precise loading order of modules.
|
Given the following module structure:
And the following module contents:
top/__init__.py
:top/b/__init__.py
:top/b/_b.py
:top/c.py
:mypy -m top
fails to resolveb.Cls
:top/c.py:2: error: Name 'b.Cls' is not defined
The text was updated successfully, but these errors were encountered: