Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[match-case] Fix narrowing of class pattern with union-argument.#19473

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
randolf-scholz wants to merge1 commit intopython:master
base:master
Choose a base branch
Loading
fromrandolf-scholz:fix_match_case_union_argument

Conversation

randolf-scholz
Copy link
Contributor

I added factorization overUnionType inside theconditional_types function.
Thentry_expanding_sum_type_to_union needed to move to the start of the function so that we expandcurrent_type before attempting factorizating the union type.

I also reformatted the docstring for better legibility.

@randolf-scholzrandolf-scholz changed the titleinital commit[match-case] Fix narrowing of class pattern with union-argument.Jul 17, 2025
current_type = try_expanding_sum_type_to_union(current_type, enum_name)

current_type = get_proper_type(current_type)
if isinstance(current_type, UnionType) and (default == current_type):
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Thedefault == current_type was necessary, otherwise quite a few tests break.
Addingor (default is None) and passingdefault=None in the recursive call also seems to break stuff. Not entirely sure what's going on there.

@github-actionsGitHub Actions
Copy link
Contributor

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

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

[match-case] class pattern narrowing with Union-argument different from equivalentisinstance call.
1 participant
@randolf-scholz

[8]ページ先頭

©2009-2025 Movatter.jp