-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Fix false positive unreachable with Any in equality comparison #20538
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
Closed
calm329
wants to merge
6
commits into
python:master
from
calm329:fix-false-unreachable-any-equality-narrowing
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
48ef44b
Fix false positive unreachable with Any in equality comparison
calm329 4c9dd70
Fix is_overlapping_none to handle Any types
calm329 e922a70
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a298d67
Fix ruff SIM101: merge isinstance calls
calm329 3416461
Add reveal_type to test to verify commit stays str | None
calm329 419c936
Revert changes to the targeted fix
calm329 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1650,3 +1650,15 @@ def x() -> None: | |
| main:4: error: Statement is unreachable | ||
| if 5: | ||
| ^~~~~ | ||
|
|
||
| [case testNoFalseUnreachableWithAnyEqualityNarrowing] | ||
| # flags: --warn-unreachable | ||
| # Regression test for https://github.com/python/mypy/issues/20532 | ||
| from typing import Any, Optional | ||
|
|
||
| def main(contents: Any, commit: Optional[str]) -> None: | ||
| if ( | ||
| contents.get("commit") == commit | ||
| and (commit is not None or 1) | ||
| ): | ||
| pass | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a |
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-snip-
Shouldn't
is_overlapping_none(Any)conceptually work? What's the fallout of making that work? (andAnyin a union, of course)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's good point, updated to fix is_overlapping_none() instead