Repository navigation
New semantic analyzer: allow replacing submodule with a variable - #6630
Conversation
JukkaL
left a comment
There was a problem hiding this comment.
Even this is a bit ad hoc, it's useful to be able to support this use case. I have a few questions about test cases, otherwise looks good (assuming tests pass).
| import lib | ||
|
|
||
| reveal_type(lib.config.x) # E: Revealed type is 'builtins.int' | ||
| reveal_type(config.x) # E: Revealed type is 'builtins.int' |
There was a problem hiding this comment.
What about trying to import lib.config as a module? Will it work? What about import lib.config as c?
There was a problem hiding this comment.
Hm, OK, I will try adding these tests.
There was a problem hiding this comment.
OK so these two have different behavior in mypy:
import lib.configactually importslib, so when one writeslib.configlater, the variable takes precedence.import lib.config as tmpfinds modulelib.configand binds it totmp, so when one writestmplater it refers to the module.
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.
| [out2] | ||
| tmp/a.py:2: error: Revealed type is 'Any' | ||
|
|
||
| [case testNewAnanlyzerTrickyImportPackage] |
There was a problem hiding this comment.
Would it be useful to an incremental mode test case as well?
There was a problem hiding this comment.
Yes, I will add an incremental test.
Although this looks like an arbitrary exception from general rules, this: