-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
I discovered this anomaly while debugging mypy in a different situation #12458.
In the final iteration of semanal_main.process_top_levels, I found that self.progress was being set = True by semanal.add_symbol_table_node.
As it turns out, this setting is ignored in process_top_levels as it's the final iteration. However, the local variable final_iteration becomes False, and that could cause problems in some future version of the code.
I suggest in semanal.add_symbol_table_node, you replace
self.progress = True
with
if not self.final_iteration:
self.progress = True
Now, regarding why a new symbol table node is being added at this late stage, it appears to me to be correct.
What's being added to module X is a dummy definition for a symbol that could not be imported from another module Y because (1) that symbol is undefined in Y or (2) X imports * from Y and that symbol was just added to Y while analyzing Y.
It appears that all possible imported names will get defined, because the SCC ordering guarantees that Y is analyzed before X in situation (2). That's assuming that X and Y are not in a from ... import * cycle.
The cyclic case should be reported as an error, in my opinion. I am filing a separate issue about that.
The dummy definition is a symbol table node with a FakeInfo object, which will get interpreted as Any in later type analysis or error reports. Are you sure you want a FakeInfo? This might lead to some bugs in a future version of the code, and you might want to create a symbol table node with type info for the real Any type.
- Mypy version used: 0.931