Spurious "progress" during final iteration
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Search for semanal_main.process_top_levels and semanal.add_symbol_table_node, then read how final_iteration and progress interact during the final pass. Done means progress is not set during that pass while the dummy symbol-table behavior remains correct; also review whether the reported FakeInfo concern requires a separate change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100