-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Bad circular imports are not rejected #61
Comments
When using the new Python-compatible syntax, the issue is that we do not detect invalid circular imports statically. This is a potential new feature -- updated labels accordingly. |
Circular imports are valid somtimes, but mypy is buggy, I hit this in #721 |
Yeah, circular imports are pretty common in larger programs (even mypy has several). Some circular imports cause the program to always fail, and mypy could detect some of these. I'll edit the title to be less confusing. |
@JukkaL in my The workaround I use is |
@o11c I saw that and it's a pretty neat trick. Alternatively, we could define a constant such as
The if statement trick also supports
It may be worth it to describe this in mypy documentation. Also, mypy could complain if a type imported as above is used without literal escapes. |
Instead of a from typing import TYPE_CHECKING
if TYPE_CHECKING:
from foo import ClassName
def f(x: 'ClassName') -> None: ... |
If
a.py
containsand
b.py
containsthen mypy compiles
a.py
without error, but the generated python throws an error because of the circular import.(Found this one while refactoring mypy itself into packages)
The text was updated successfully, but these errors were encountered: