Skip to content

Fix matching against union of tuples #19600

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

saulshanabrook
Copy link
Contributor

@saulshanabrook saulshanabrook commented Aug 6, 2025

This pull request fixes handling of union types containing tuples in match statements. Previously, when a tuple was part of a union, all its items would be unioned together and treated as a homogeneous tuple of that union type, which was incorrect.

It still fallbacks on this behavior if we there are multiple tuples in the union with Unpack in them, but otherwise now it should be handled correctly.

I attempted to keep as much of the existing semantics the same besides for this change. I also tried to keep the performance roughly similar, not unioning types more than needed.

Closes #19599

@saulshanabrook saulshanabrook marked this pull request as draft August 6, 2025 20:22

This comment has been minimized.

@saulshanabrook saulshanabrook marked this pull request as ready for review August 6, 2025 20:40

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

github-actions bot commented Aug 7, 2025

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

@saulshanabrook
Copy link
Contributor Author

This is now ready for review.

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.

Matching tuple against union merges field types
1 participant