Skip to content
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

mypy duplicates reveal_type notes with partial types #18511

Open
A5rocks opened this issue Jan 22, 2025 · 3 comments
Open

mypy duplicates reveal_type notes with partial types #18511

A5rocks opened this issue Jan 22, 2025 · 3 comments
Labels
bug mypy got something wrong topic-reveal-type reveal_type() and reveal_locals()

Comments

@A5rocks
Copy link
Collaborator

A5rocks commented Jan 22, 2025

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
@A5rocks A5rocks added bug mypy got something wrong topic-reveal-type reveal_type() and reveal_locals() labels Jan 22, 2025
@tyralla
Copy link
Collaborator

tyralla commented 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 None in the first and can be either None or str in 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
Copy link
Collaborator Author

A5rocks commented 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
Copy link
Collaborator

tyralla commented 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-redefinition disabled, things could generally stay as they are. But @JukkaL should know this more certainly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-reveal-type reveal_type() and reveal_locals()
Projects
None yet
Development

No branches or pull requests

2 participants