Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Closed
Description
- Are you reporting a bug, or opening a feature request?: bug
- What is the actual behavior/output?
Given the following (cut down) loop code, mypy identifies incorrectly that the print statement cannot be reached.
last=Nonereveal_type(last)# Revealed type is 'None'forvalinrange(10):reveal_type(last)# Revealed type is 'None'iflastisnotNoneandlast<2:print("apparently unreachable")reveal_type(last)# no outputreveal_type(last)# Revealed type is 'None'last=valreveal_type(last)# Revealed type is 'builtins.int*'
My original code also used the value oflast within the conditional; that was also warned about being not evaluated.
Notably, runningmypy --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 explicitOptional[int] annotation tolast.
- What is the behavior/output you expect?
I thinkmypy 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 theif last is not None branch,last should be of typeint.
- What are the versions of mypy and Python you are using? mypy 0.770, Python 3.5.2
Do you see the same issue after installing mypy from Git master? yes (tested at125728a) - What are the mypy flags you are using?
--warn-unreachable