Better handling of generics when narrowing#20863
Open
hauntsaninja wants to merge 2 commits intopython:masterfrom
Open
Better handling of generics when narrowing#20863hauntsaninja wants to merge 2 commits intopython:masterfrom
hauntsaninja wants to merge 2 commits intopython:masterfrom
Conversation
Notably we preserve behaviour on the testNarrowingCollections test I added
for more information, see https://pre-commit.ci
hauntsaninja
commented
Feb 22, 2026
| if from_equality: | ||
| # We erase generic args because values with different generic types can compare equal | ||
| # For instance, cast(list[str], []) and cast(list[int], []) | ||
| proposed_type = shallow_erase_type_for_equality(proposed_type) |
Collaborator
Author
There was a problem hiding this comment.
this is the one line difference (the rest is just refactoring for clarity)
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: graphql-core (https://github.com/graphql-python/graphql-core)
- tests/execution/test_resolve.py:322: error: Value of type "list[SourceLocation] | None" is not indexable [index]
rotki (https://github.com/rotki/rotki)
+ rotkehlchen/tests/integration/test_premium.py:820: error: Statement is unreachable [unreachable]
+ rotkehlchen/tests/integration/test_premium.py:834: error: Statement is unreachable [unreachable]
xarray (https://github.com/pydata/xarray)
+ xarray/tests/test_dataarray.py:291: error: Unused "type: ignore" comment [unused-ignore]
|
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
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.
Notably we preserve behaviour on the
testNarrowingCollectionstest I added in a previous PRCloses #20673