Skip to content

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

Draft
randolf-scholz wants to merge 8 commits into
python:mainfrom
randolf-scholz:fix-issue-118524-match-union
Draft

gh-106246: Allow the use of unions as match patterns#118644
randolf-scholz wants to merge 8 commits into
python:mainfrom
randolf-scholz:fix-issue-118524-match-union

Conversation

@randolf-scholz

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

Copy link
Copy Markdown
Contributor

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

Comment thread Lib/test/test_patma.py
@tmke8

tmke8 commented May 6, 2024

Copy link
Copy Markdown
Contributor

Thanks for working on this!

Comment thread Lib/test/test_patma.py Outdated
Comment thread Lib/test/test_patma.py
@randolf-scholz
randolf-scholz force-pushed the fix-issue-118524-match-union branch from b38a4cb to 767f5dc Compare May 7, 2024 13:49
@sobolevn

sobolevn commented May 8, 2024

Copy link
Copy Markdown
Member

Too late for 3.13 :(
This will go into 3.14

@gvanrossum

Copy link
Copy Markdown
Member

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

Comment thread Misc/NEWS.d/next/Core and Builtins/2024-05-02-20-16-12.gh-issue-118524.B4rIYi.rst Outdated
@tmke8

tmke8 commented Oct 8, 2024

Copy link
Copy Markdown
Contributor

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

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

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 👍

Comment thread Python/ceval.c Outdated
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[match-case] Allow matching Union types

5 participants