-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Don't error on re-exported imports in cycles. Fixes #4049. #4495
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
Changes from all commits
1dc60ec
02c401b
5edf2af
9903110
9f36fec
3cc7e2e
2255e1c
bc57349
f78ae95
b5bf41d
2a37e80
8a222da
06dbcc6
2efc322
f7c3d43
5adf42b
f675706
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1955,3 +1955,85 @@ import c | |
tmp/b.py:1: error: Cannot find module named 'c' | ||
main:1: error: Cannot find module named 'c' | ||
main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) | ||
|
||
[case testImportFromReExportInCycle] | ||
from m import One | ||
reveal_type(One) | ||
[file m/__init__.py] | ||
from .one import One | ||
from .two import Two | ||
reveal_type(One) | ||
[file m/one.py] | ||
class One: | ||
pass | ||
[file m/two.py] | ||
from m import One | ||
reveal_type(One) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that references to
Similarly, if we make If we create a subclass of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catches! I think these are probably fixable by adding more third-pass visits to different node types to propagate type info that we missed in second pass due to the cycle, but it does begin to feel a bit like a game of whack-a-mole. |
||
x: One | ||
reveal_type(x) | ||
# TODO also resolve One correctly when used as base class (currently resolves as Any) | ||
class Two: | ||
pass | ||
[out] | ||
tmp/m/two.py:2: error: Revealed type is 'def () -> m.one.One' | ||
tmp/m/two.py:4: error: Revealed type is 'm.one.One' | ||
tmp/m/__init__.py:3: error: Revealed type is 'def () -> m.one.One' | ||
main:2: error: Revealed type is 'def () -> m.one.One' | ||
|
||
[case testImportReExportInCycle] | ||
from m import One | ||
reveal_type(One) | ||
[file m/__init__.py] | ||
from .one import One | ||
from .two import Two | ||
reveal_type(One) | ||
[file m/one.py] | ||
class One: | ||
pass | ||
[file m/two.py] | ||
import m | ||
reveal_type(m.One) | ||
x: m.One | ||
reveal_type(x) | ||
class Two: | ||
pass | ||
[out] | ||
tmp/m/two.py:2: error: Revealed type is 'def () -> m.one.One' | ||
tmp/m/two.py:4: error: Revealed type is 'm.one.One' | ||
tmp/m/__init__.py:3: error: Revealed type is 'def () -> m.one.One' | ||
main:2: error: Revealed type is 'def () -> m.one.One' | ||
|
||
[case testImportReExportedNamedTupleInCycle] | ||
from m import One | ||
[file m/__init__.py] | ||
from .one import One | ||
from .two import Two | ||
[file m/one.py] | ||
from typing import NamedTuple | ||
class One(NamedTuple): | ||
name: str | ||
[file m/two.py] | ||
import m | ||
x = m.One(name="Foo") | ||
reveal_type(x.name) | ||
class Two: | ||
pass | ||
[out] | ||
tmp/m/two.py:3: error: Revealed type is 'builtins.str' | ||
|
||
[case testImportReExportedTypeAliasInCycle] | ||
from m import One | ||
[file m/__init__.py] | ||
from .one import One | ||
from .two import Two | ||
[file m/one.py] | ||
from typing import Union | ||
One = Union[int, str] | ||
[file m/two.py] | ||
import m | ||
x: m.One | ||
reveal_type(x) | ||
class Two: | ||
pass | ||
[out] | ||
tmp/m/two.py:3: error: Revealed type is 'Union[builtins.int, builtins.str]' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, it would be nice to test how all these references work with type aliases and named tuples, for example. (In separate tese cases.)