FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Better handling of generics when narrowing by hauntsaninja · Pull Request #20863 · python/mypy · GitHub

Repository navigation

Better handling of generics when narrowing - #20863

Merged
hauntsaninja merged 2 commits into
python:masterfrom
hauntsaninja:narrow94
Feb 26, 2026
Merged

hauntsaninja merged 2 commits into
python:masterfrom
hauntsaninja:narrow94

Conversation

hauntsaninja commented Feb 22, 2026 •
edited
Loading

Copy link
Copy Markdown
Collaborator

Notably we preserve behaviour on the testNarrowingCollections test I added in a previous PR

Closes #20673

hauntsaninja and others added 2 commits February 22, 2026 13:32
Notably we preserve behaviour on the testNarrowingCollections test I added
Comment thread mypy/checker.py
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)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

this is the one line difference (the rest is just refactoring for clarity)

Copy link
Copy Markdown
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]

Copy link
Copy Markdown
Collaborator Author

Will merge this soon!

S = Callable[[B], "T"]

def f(x: S, y: T):
if x == y: # E: Unsupported left operand type for == ("Callable[[B], T]")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is this related to a recursive callable type?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

No, it's related to fixtures

hauntsaninja merged commit c09b174 into python:master Feb 26, 2026
24 checks passed
hauntsaninja deleted the narrow94 branch February 26, 2026 18:39
hauntsaninja added a commit to hauntsaninja/mypy that referenced this pull request Apr 2, 2026
Fixes python#21143 (on the same lines as python#20704)

I also update a comment that is a little out of date since python#20863
and code in checkexpr.py that is out of date for modern typeshed
hauntsaninja added a commit that referenced this pull request Apr 3, 2026
Fixes #21143 (on the same lines as #20704, i.e. there still exists a
deeper fix that could be made)

I also update a comment that is a little out of date since #20863 and
code in checkexpr.py that is out of date for modern typeshed
hauntsaninja added a commit that referenced this pull request Apr 5, 2026
Fixes #21143 (on the same lines as #20704, i.e. there still exists a
deeper fix that could be made)

I also update a comment that is a little out of date since #20863 and
code in checkexpr.py that is out of date for modern typeshed
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL