Repository navigation
New semantic analyzer: allow replacing submodule with a variable #6630
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
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 |
|---|---|---|
|
|
@@ -2049,3 +2049,65 @@ from pp import x as y | |
| def __getattr__(attr): ... | ||
| [out2] | ||
| tmp/a.py:2: error: Revealed type is 'Any' | ||
|
|
||
| [case testNewAnanlyzerTrickyImportPackage] | ||
| from lib import config | ||
| import lib | ||
|
|
||
| reveal_type(lib.config.x) # E: Revealed type is 'builtins.int' | ||
| reveal_type(config.x) # E: Revealed type is 'builtins.int' | ||
|
Collaborator
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. What about trying to import
Member
Author
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. Hm, OK, I will try adding these tests.
Member
Author
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. OK so these two have different behavior in mypy:
At runtime variable always wins. Fixing the second one is non-trivial, because we need to check whether there is a "shadowing" variable at every submodule level. Also this is kind of corner case to a corner case. |
||
|
|
||
| [file lib/__init__.py] | ||
| from lib.config import config | ||
|
|
||
| [file lib/config.py] | ||
| class Config: | ||
| x: int | ||
|
|
||
| config = Config() | ||
| [builtins fixtures/module.pyi] | ||
|
|
||
| [case testNewAnanlyzerTrickyImportPackageAlt] | ||
| import lib.config | ||
| import lib.config as tmp | ||
|
|
||
| reveal_type(lib.config.x) # E: Revealed type is 'builtins.int' | ||
| # TODO: this actually doesn't match runtime behavior, variable wins. | ||
| tmp.x # E: Module has no attribute "x" | ||
|
|
||
| [file lib/__init__.py] | ||
| from lib.config import config | ||
|
|
||
| [file lib/config.py] | ||
| class Config: | ||
| x: int | ||
|
|
||
| config = Config() | ||
| [builtins fixtures/module.pyi] | ||
|
|
||
| [case testNewAnanlyzerTrickyImportPackage_incremental] | ||
| import a | ||
|
|
||
| [file a.py] | ||
| from lib import config | ||
| import lib | ||
|
|
||
| [file a.py.2] | ||
| from lib import config | ||
| import lib | ||
|
|
||
| reveal_type(lib.config.x) | ||
| reveal_type(config.x) | ||
|
|
||
| [file lib/__init__.py] | ||
| from lib.config import config | ||
|
|
||
| [file lib/config.py] | ||
| class Config: | ||
| x: int | ||
|
|
||
| config = Config() | ||
| [builtins fixtures/module.pyi] | ||
| [out2] | ||
| tmp/a.py:4: error: Revealed type is 'builtins.int' | ||
| tmp/a.py:5: error: Revealed type is 'builtins.int' | ||
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.
Would it be useful to an incremental mode test case as well?
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.
Yes, I will add an incremental test.