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

Further improve match statement narrowing against unions by hauntsaninja · Pull Request #20744 · python/mypy · GitHub

Repository navigation

Further improve match statement narrowing against unions - #20744

Merged
hauntsaninja merged 3 commits into
python:masterfrom
hauntsaninja:matchtup
Feb 11, 2026
Merged

hauntsaninja merged 3 commits into
python:masterfrom
hauntsaninja:matchtup

Conversation

hauntsaninja commented Feb 5, 2026 •
edited
Loading

Copy link
Copy Markdown
Collaborator

I realised there is a simpler and more complete approach than the one taken in #19600.
This adds the new "Step 2" to the original code. Best way to review the diff is probably to check it out and review it squashed with #19600 , but really the net logic change is just "Step 2"

Fixes #15190
Fixes #17549
Fixes #17600
Mostly fixes #18039
Helps with things in #19081

I realised there is a simpler and more powerful approach than the one
taken in python#19600. This basically adds the new "Step 2" to the original
code.

This comment has been minimized.

hauntsaninja marked this pull request as draft February 5, 2026 08:24

This comment has been minimized.

hauntsaninja marked this pull request as ready for review February 5, 2026 21:40
hauntsaninja mentioned this pull request Feb 5, 2026
hauntsaninja requested a review from JukkaL February 5, 2026 22:58

JukkaL left a comment

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

Thanks, looks good -- just one potential code path that seems redundant.

Comment thread mypy/checkpattern.py Outdated
elif isinstance(current_type, AnyType):
inner_type: Type = AnyType(TypeOfAny.from_another_any, current_type)
inner_types = [inner_type] * len(o.patterns)
elif isinstance(current_type, TupleType):

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

Second check against TupleType that can never be taken?

Copy link
Copy Markdown
Contributor

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

hauntsaninja merged commit 9752e19 into python:master Feb 11, 2026
23 checks passed
hauntsaninja deleted the matchtup branch February 11, 2026 19:39
hauntsaninja added a commit that referenced this pull request Mar 4, 2026
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

2 participants


Back | FazBrowse Home | New Git URL