Skip to content

gh-106246: Allow the use of unions as match patterns #118644

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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

randolf-scholz
Copy link
Contributor

@randolf-scholz randolf-scholz commented May 6, 2024

Fixes #106246

Modified version of #118525 that supports using subpatterns in unions.

added tests:

  1. test_patma_union_type
  2. test_patma_union_no_match
  3. test_union_type_positional_subpattern
  4. test_union_type_keyword_subpattern
  5. test_patma_union_arg
  6. test_patma_union_kwarg
  7. test_patma_union_arg_no_match
  8. test_patma_union_kwarg_no_match
  9. test_union_type_match_second_member
  10. test_generic_type
  11. test_legacy_generic_type
  12. test_class_or_union_not_specialform
  13. test_legacy_union_type
  14. test_expanded_union_mirrors_isinstance_success
  15. test_expanded_union_mirrors_isinstance_failure
  16. test_union_type_mirrors_isinstance_success
  17. test_union_type_mirrors_isinstance_failure
  18. test_generic_union_type

@tmke8
Copy link
Contributor

tmke8 commented May 6, 2024

Thanks for working on this!

@randolf-scholz randolf-scholz force-pushed the fix-issue-118524-match-union branch from b38a4cb to 767f5dc Compare May 7, 2024 13:49
@sobolevn
Copy link
Member

sobolevn commented May 8, 2024

Too late for 3.13 :(
This will go into 3.14

@gvanrossum
Copy link
Member

While you have some time, I recommend adding some great docs for the new feature as well.

@tmke8
Copy link
Contributor

tmke8 commented Oct 8, 2024

Is the plan still to land this in 3.14?

@randolf-scholz randolf-scholz force-pushed the fix-issue-118524-match-union branch from c4bff3d to a52fd60 Compare July 20, 2025 15:58
@randolf-scholz randolf-scholz force-pushed the fix-issue-118524-match-union branch from a52fd60 to 114f250 Compare July 20, 2025 16:01
@randolf-scholz randolf-scholz force-pushed the fix-issue-118524-match-union branch from 914fadc to eeef8cd Compare July 21, 2025 09:43
@randolf-scholz randolf-scholz marked this pull request as draft July 21, 2025 09:44
@randolf-scholz randolf-scholz force-pushed the fix-issue-118524-match-union branch from eeef8cd to 4829f23 Compare July 21, 2025 09:59
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

I agree, let's also add some examples to the docs 👍

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.

[match-case] Allow matching Union types
5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy