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

warn_unreachable false positive when reassigning in loop #15917

Closed
Garrett-R opened this issue Aug 21, 2023 · 2 comments
Closed

warn_unreachable false positive when reassigning in loop #15917

Garrett-R opened this issue Aug 21, 2023 · 2 comments
Labels
bug mypy got something wrong topic-reachability Detecting unreachable code topic-type-narrowing Conditional type narrowing / binder

Comments

@Garrett-R
Copy link

Garrett-R commented Aug 21, 2023

Bug Report

To Reproduce

-Run this code with warn_unreachable enabled:

x: int|None = None
x = None
for _ in range(2):
    if x is None:
        print('None')
        x = 2
    else:
        print('Not None')

(Mypy playground)

Expected Behavior

No errors.

Actual Behavior

main.py:8: error: Statement is unreachable  [unreachable]

(this is wrong, the script indeed hits line 8 and prints Not None)

Your Environment

  • Mypy version used: 1.5.1
  • Mypy configuration options from mypy.ini (and other config files): warn_unreachable = true
  • Python version used: 3.11.4
@Garrett-R Garrett-R added the bug mypy got something wrong label Aug 21, 2023
@JelleZijlstra JelleZijlstra added the topic-reachability Detecting unreachable code label Aug 21, 2023
@AlexWaygood AlexWaygood added the topic-type-narrowing Conditional type narrowing / binder label Aug 21, 2023
@erictraut
Copy link

I think this may be a duplicate of #14987, #11612, #10634, #8865, and #8721. All of these seem to be manifestations of the same underlying bug.

@Garrett-R
Copy link
Author

Ah yes, you're right, my bad! I had tried searching before creating this, but somehow missed all those. Closing.

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-reachability Detecting unreachable code topic-type-narrowing Conditional type narrowing / binder
Projects
None yet
Development

No branches or pull requests

4 participants