-
-
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
Flag None
check on value that cannot be None
#18386
Comments
Both Maybe worth closing this to make a bug report? Or someone can change tags (I can't :'( ). |
Forgot to add, this affects Mypy 1.14.1 with Python 3.14, using Switching the tag from feature to bug is fine with me :) |
It isn't included in that. Maybe thumbs up #18078! |
Here is a full example: from random import randrange
def f(x: int) -> int | None:
return None if x == 0 else 2 * x
def g(x: int) -> int:
return 2 * x
if __name__ == '__main__':
if f(randrange(10)) is None:
print('f: got 0')
if g(randrange(10)) is None: # <-- unreachable but not flagged
print('g: got 0')
|
Say I have function that maybe returns
None
and I check the result:I rewrite the function so that it never returns
None
:Now the
is None
check makes no sense -- it will always fail. This is a mistake introduced in refactoring and it should be flagged. (And similar foris not None
checks)In Rust I don't think this kind of error is possible:
The text was updated successfully, but these errors were encountered: