-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Reachable code in loop marked unreachable #8721
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
Labels
bug
mypy got something wrong
priority-0-high
topic-reachability
Detecting unreachable code
topic-type-narrowing
Conditional type narrowing / binder
Comments
PeterJCLaw
added a commit
to PeterJCLaw/srcomp
that referenced
this issue
Apr 25, 2020
This seems pretty bad, as it can result in false negatives. Mypy should give an error when reading the value of |
I think #8865 is about the same problem. |
False positives are also possible without partials, see for example:
|
tyralla
added a commit
to tyralla/mypy
that referenced
this issue
Jan 9, 2025
Fixes python#18348 Fixes python#13973 Fixes python#11612 Fixes python#8721 Fixes python#8865 Fixes python#7204 I manually checked all the listed issues. Some of them were already partly fixed by python#18180.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
mypy got something wrong
priority-0-high
topic-reachability
Detecting unreachable code
topic-type-narrowing
Conditional type narrowing / binder
Given the following (cut down) loop code, mypy identifies incorrectly that the print statement cannot be reached.
My original code also used the value of
last
within the conditional; that was also warned about being not evaluated.Notably, running
mypy --no-warn-unreachable
still doesn't give any output for thereveal_type
in theif
branch.Happily this issue can be worked around by adding an explicit
Optional[int]
annotation tolast
.I think
mypy
should considerlast
to beOptional[int]
in the early part of the loop, rather than just beingNone
. That would fix the unreachable warning as well as potentially being more correct.Within the
if last is not None
branch,last
should be of typeint
.Do you see the same issue after installing mypy from Git master? yes (tested at 125728a)
--warn-unreachable
The text was updated successfully, but these errors were encountered: