-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
False positive "Statement is unreachable" when checking if typevar is None #18126
Comments
There's something wrong with this logic. When checking for narrowing in mypy/test-data/unit/check-isinstance.test Lines 2210 to 2227 in 3b00002
I don't think that this approach is sound: narrowing a lone TypeVar is a common problem, it shouldn't erroneously mark code as unreachable.
I tried to modify the binder to keep track of whether every type in frame was updated via an |
Bug Report
Mypy doesn't seem to like it when you check if an argument with typevar type is checked to see if it is
None
. It incorrectly reportserror: Statement is unreachable [unreachable]
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&flags=strict%2Cwarn-unreachable&gist=ceb8193f19f8b53a55dea70fad802469
Run mypy with
--warn-unreachable
flagExpected Behavior
No errors
Actual Behavior
The error seems to only happen when checking if arg is
None
, but not with other types. For example, I tired changingif arg is None:
line to the following and these were the results.if arg is True:
-> no errorsif isinstance(arg, int):
-> no errorsif isinstance(arg, type(None)):
-> unreachable errorif arg == None:
-> No errorAlso, changing the type to
T | None
removes the error as well.Your Environment
mypy.ini
(and other config files):warn_unreachable = True
The text was updated successfully, but these errors were encountered: