-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
gh-140253: Improve the syntax error from an ill-positioned double-star subpattern #140254
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
Changes from 4 commits
0368491
b203743
a4a49d7
bc0eb7d
49876df
78ad464
6f3559e
2a91f3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -252,7 +252,16 @@ def testSyntaxErrorOffset(self): | |
| check('[\nfile\nfor str(file)\nin\n[]\n]', 3, 5) | ||
| check('[file for\n str(file) in []]', 2, 2) | ||
| check("ages = {'Alice'=22, 'Bob'=23}", 1, 9) | ||
| check('match ...:\n case {**rest, "key": value}:\n ...', 2, 19) | ||
| check(dedent("""\ | ||
| match ...: | ||
| case {**rest1, "after": after}: | ||
| ... | ||
| """), 2, 11) | ||
| check(dedent("""\ | ||
| match ...: | ||
| case {"before": before, **rest2, "after": after}: | ||
| ... | ||
| """), 2, 29) | ||
|
Comment on lines
+255
to
+264
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made it multi-line with dedent so it's easier to read--these tests were missing a case where some items were placed before the double-star pattern. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm using |
||
| check("[a b c d e f]", 1, 2) | ||
| check("for x yfff:", 1, 7) | ||
| check("f(a for a in b, c)", 1, 3, 1, 15) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -370,12 +370,6 @@ | |
| Traceback (most recent call last): | ||
| SyntaxError: invalid syntax | ||
| >>> match ...: | ||
| ... case {**rest, "key": value}: | ||
| ... ... | ||
| Traceback (most recent call last): | ||
| SyntaxError: invalid syntax | ||
| >>> match ...: | ||
| ... case {**_}: | ||
| ... ... | ||
|
|
@@ -2240,7 +2234,7 @@ | |
| Traceback (most recent call last): | ||
| SyntaxError: invalid character '£' (U+00A3) | ||
| Invalid pattern matching constructs: | ||
| Invalid pattern matching constructs: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was likely an accidental indentation, fixed it by the way. |
||
| >>> match ...: | ||
| ... case 42 as _: | ||
|
|
@@ -2302,6 +2296,18 @@ | |
| Traceback (most recent call last): | ||
| SyntaxError: positional patterns follow keyword patterns | ||
| >>> match ...: | ||
| ... case {**double_star, "spam": "eggs"}: | ||
| ... ... | ||
| Traceback (most recent call last): | ||
| SyntaxError: double star pattern must be the last (right-most) subpattern in the mapping pattern | ||
| >>> match ...: | ||
| ... case {"foo": 1, **double_star, "spam": "eggs"}: | ||
| ... ... | ||
| Traceback (most recent call last): | ||
| SyntaxError: double star pattern must be the last (right-most) subpattern in the mapping pattern | ||
Eclips4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Uses of the star operator which should fail: | ||
| A[:*b] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Wrong placement of a double-star pattern inside a mapping pattern now throws a specialized syntax error. | ||
| Contributed by Bartosz Sławecki in :gh:`140253`. |
Uh oh!
There was an error while loading. Please reload this page.