-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[red-knot] support narrowing on or patterns in matches #17030
Conversation
|
Move the pattern guard field from PatternPredicateKind to PatternPredicate. This better matches the ast and saves us from storing a bunch of Nones in or patterns. Also, it will make things a bit cleaner if we start to look at guards in the match case narrowing
case "foo" | 42 | None: | ||
reveal_type(x) # revealed: Literal["foo", 42] | None | ||
case "foo" | tuple(): | ||
# kill lamumbo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has this been randomly generated by an LLM or what is going on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also curious how this came to be here 😆 but the PR looks great otherwise, so I'm just going to remove this line and merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
case "foo" | 42 | None: | ||
reveal_type(x) # revealed: Literal["foo", 42] | None | ||
case "foo" | tuple(): | ||
# kill lamumbo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also curious how this came to be here 😆 but the PR looks great otherwise, so I'm just going to remove this line and merge.
Summary
Part of #13694
Narrow in or-patterns by taking the type union of the type constraints in each disjunct pattern.
Test Plan
Add new tests to narrow/match.md