mypy duplicates reveal_type notes with partial types #18511
Copy link
Copy link
Closed
Labels
bugmypy got something wrongmypy got something wrongtopic-reveal-typereveal_type() and reveal_locals()reveal_type() and reveal_locals()
Description
Bug Report
There's two notes from a single reveal_type with a partial type in a loop.
To Reproduce
def main() -> None:
x = None
while True:
reveal_type(x)
x = ""(the outer function is only necessary to make sure a transition to --local-partial-types doesn't render this test case useless)
Expected Behavior
main.py:4: note: Revealed type is "Union[builtins.str, None]"
Success: no issues found in 1 source file
Actual Behavior
main.py:4: note: Revealed type is "None"
main.py:4: note: Revealed type is "Union[builtins.str, None]"
Success: no issues found in 1 source file
Your Environment
I assume this was caused by #18180. Checked on mypy playground.
- Mypy version used: master
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.12
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-reveal-typereveal_type() and reveal_locals()reveal_type() and reveal_locals()
Activity
tyralla commentedon Jan 23, 2025
This could also happen before #18180 (when loops were repeatedly checked for other reasons), but you are right that #18180 increases the number of cases where this can happen. I realised this when working on it but was unsure whether this behaviour was a feature or a bug. The current behaviour tells us that the type must be
Nonein the first and can be eitherNoneorstrin subsequent iterations. If there is consent that this is more confusing than helpful, we could likely extend the logic of #18433 to remove "early" results.A5rocks commentedon Jan 23, 2025
I think it's worth it to stop these weird results by preventing early outputs from showing. (I think it's surprising more than confusing but surprising isn't a fun place to be.)
That is unless #18516 includes redoing partial types.
tyralla commentedon Jan 24, 2025
I guess #18516 would not remove the need to check some loops repeatedly and, hence, would not fix this issue automatically. Additionally, I suppose, with
--allow-redefinitiondisabled, things could generally stay as they are. But @JukkaL should know this more certainly.Avoid false `unreachable` and `redundant-expr` warnings in loops more…
Avoid false `unreachable`, `redundant-expr`, and `redundant-casts` wa…