-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Rework narrowing logic for equality and identity #20492
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This comment has been minimized.
This comment has been minimized.
6e89ffd to
9e351d1
Compare
This comment has been minimized.
This comment has been minimized.
b29984a to
4dbd107
Compare
This comment has been minimized.
This comment has been minimized.
f574fef to
4a552d5
Compare
This comment has been minimized.
This comment has been minimized.
d143ddc to
ca5120d
Compare
This comment has been minimized.
This comment has been minimized.
bdfc626 to
586d2a1
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
0b15de0 to
7bc5dac
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This was referenced Jan 16, 2026
hauntsaninja
added a commit
that referenced
this pull request
Jan 16, 2026
This is a follow up to #20492 that is pure refactoring. I separated it out to make that change easier to review. We inline `narrow_identity_equality_comparison`, improve comments, etc. There is some further refactoring later in my commit stack too.
hauntsaninja
added a commit
that referenced
this pull request
Jan 16, 2026
Requested in #20492 (comment) Regression for the Never's in #18524 (comment)
hauntsaninja
added a commit
to hauntsaninja/mypy
that referenced
this pull request
Jan 17, 2026
This relates to changes made in python#20492
Collaborator
|
Noticed a minor regression in Home Assistant with # mypy: warn-unreachable
from enum import IntFlag
class WeatherFeature(IntFlag):
FORECAST_DAILY = 1
FORECAST_HOURLY = 2
FORECAST_TWICE_DAILY = 4
def func(supported_features: int) -> None:
reveal_type(supported_features)
if (supported_features & WeatherFeature.FORECAST_DAILY) == 0:
print("Hello World") # <-- This should work fine |
Collaborator
Author
|
Thanks, I have a follow up commit that will fix this case |
hauntsaninja
added a commit
that referenced
this pull request
Jan 21, 2026
Fixes some of the primer regressions from #20492 Fixes #19753 This should also happen to fix the case mentioned by cdce8p in #20492 (comment)
hauntsaninja
added a commit
to hauntsaninja/mypy
that referenced
this pull request
Jan 21, 2026
This relates to changes made in python#20492
hauntsaninja
added a commit
to hauntsaninja/mypy
that referenced
this pull request
Jan 22, 2026
This relates to changes made in python#20492
hauntsaninja
added a commit
to hauntsaninja/mypy
that referenced
this pull request
Jan 22, 2026
This relates to changes made in python#20492
hauntsaninja
added a commit
to hauntsaninja/mypy
that referenced
this pull request
Jan 22, 2026
This relates to changes made in python#20492
hauntsaninja
added a commit
to hauntsaninja/mypy
that referenced
this pull request
Jan 28, 2026
This relates to changes made in python#20492
hauntsaninja
added a commit
to hauntsaninja/mypy
that referenced
this pull request
Jan 28, 2026
This relates to changes made in python#20492
hauntsaninja
added a commit
to hauntsaninja/mypy
that referenced
this pull request
Jan 28, 2026
This relates to changes made in python#20492
JukkaL
pushed a commit
that referenced
this pull request
Jan 28, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Mypy does not narrow as much as it could, which results in false positives.
We would also like to narrow based on containment. The PR for that was previously reverted due to inconsistencies between narrowing via equality and via containment. This fixes the inconsistency on the equality side and paves the road for adding narrowing via containment. That is, we lay groundwork for fixing #17864 and fixing #17841
Fixes #18524
Fixes #20041
Fixes #17162
Fixes #16830
Fixes #13704
Fixes #7642
Fixes #3964