Skip to content
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

Have multiple passes by SemanticAnalyzerPass3 to resolve more forward references. #4095

Closed
ilevkivskyi opened this issue Oct 10, 2017 · 5 comments
Labels
bug mypy got something wrong priority-2-low

Comments

@ilevkivskyi
Copy link
Member

As mentioned in #3952 (comment) some double-forward references (and other corner cases) are currently not resolved. For example this does not work:

x: A
A = B
B = List[int]

This is because third pass happens only once. In checker.py we have deferred nodes, and there are mini-passes over them until they are all done, I think we can adopt the same idea here and have repeated third passes.

This is however low priority since these edge cases are extremely rare and don't cause crashes, only false positives.

@ilevkivskyi
Copy link
Member Author

Related #731

@gvanrossum
Copy link
Member

Also that particular example won't work -- even if you protect the x: A from crashing (e.g. using x: 'A'), A = B will still crash.

@ilevkivskyi
Copy link
Member Author

Yes, this is just a simple illustration, there are other more complex situations that will work at runtime, but not in mypy, all of them are purely "academic" however.

@ilevkivskyi
Copy link
Member Author

Even this one formally speaking can be protected by if TYPE_CHECKING: ...

@ilevkivskyi
Copy link
Member Author

This now works correctly with the new analyzer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-2-low
Projects
None yet
Development

No branches or pull requests

2 participants