Skip to content
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

Fix call patterns that contain as-expression on the kwargs #2749

Merged
merged 1 commit into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
(#2686)
- Fix cases that contain multiple top-level as-expressions, like `case 1 as a, 2 as b`
(#2716)
- Fix call patterns that contain as-expressions with keyword arguments, like
`case Foo(bar=baz as quux)` (#2749)
- No longer color diff headers white as it's unreadable in light themed terminals
(#2691)
- Tuple unpacking on `return` and `yield` constructs now implies 3.8+ (#2700)
Expand Down
2 changes: 1 addition & 1 deletion src/blib2to3/Grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ arglist: argument (',' argument)* [',']
argument: ( test [comp_for] |
test ':=' test |
test 'as' test |
test '=' test |
test '=' asexpr_test |
'**' test |
'*' test )

Expand Down
14 changes: 14 additions & 0 deletions tests/data/pattern_matching_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,17 @@ def func(match: case, case: match) -> case:

case 4 as d, (5 as e), (6 | 7 as g), *h:
pass


match bar1:
case Foo(aa=Callable() as aa, bb=int()):
print(bar1.aa, bar1.bb)
case _:
print("no match", "\n")


match bar1:
case Foo(
normal=x, perhaps=[list, {an: d, dict: 1.0}] as y, otherwise=something, q=t as u
):
pass