-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add check for comparisons like None in list/set/tuple
#17154
base: master
Are you sure you want to change the base?
Add check for comparisons like None in list/set/tuple
#17154
Conversation
…riables to not include None
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
…ed at the end of the if condition (preventing exceptions if right has no attribute "items")
…' into detect-None-in-default-iterables
This comment has been minimized.
This comment has been minimized.
The new feature is ready and I tested it on all kinds of code samples, but something in the automatic tests that I added in the check-optional.test file got stuck. |
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Are there plans to merge this PR? Would be a great feature! |
Implements #17152
Fixes #17149
Summary
This PR adds to mypy the ability to recognize conditions like
if None in [a, b, c]:
and refine the types ofa, b, c
in the relevant scope. The supported expressions areListExpr, TupleExpr, SetExpr
.