Skip to content
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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

eladshoshani
Copy link

@eladshoshani eladshoshani commented Apr 23, 2024

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 of a, b, c in the relevant scope. The supported expressions are ListExpr, TupleExpr, SetExpr.

This comment has been minimized.

This comment has been minimized.

@eladshoshani eladshoshani marked this pull request as ready for review April 23, 2024 11:49
@eladshoshani
Copy link
Author

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.
I don't have any more time right now to work on the feature, so I leave the correction/deletion of these tests to the CR

Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@KazMiddelhoek
Copy link

Are there plans to merge this PR? Would be a great feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type refinement does not work with None in [a, b, c], any(), or all() checks
2 participants