-
-
Couldn't load subscription status.
- Fork 33.2k
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
Merged
+671
−514
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0368491
Add and use `invalid_mapping_pattern`
bswck b203743
Add syntax error message tests
bswck a4a49d7
Add syntax error offset tests
bswck bc0eb7d
Add news entry
bswck 49876df
Merge branch 'main' into invalid-double-star-mapping
bswck 78ad464
Require a comma in the preceding items sub-pattern
bswck 6f3559e
Regenerate the parser
bswck 2a91f3f
Add nested mapping test
bswck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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,24 @@ | |
| 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
|
||
| >>> match ...: | ||
| ... case {"spam": "eggs", "b": {**d, "ham": "bacon"}}: | ||
| ... ... | ||
| Traceback (most recent call last): | ||
| SyntaxError: double star pattern must be the last (right-most) subpattern in the mapping pattern | ||
|
|
||
| Uses of the star operator which should fail: | ||
|
|
||
| A[:*b] | ||
|
|
||
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Core_and_Builtins/2025-10-17-14-38-10.gh-issue-140253.gCqFaL.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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`. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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.
Uh oh!
There was an error while loading. Please reload this page.
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 using
rest1andrest2names here so that they differ from what is in the grammar file and perhaps in other places. Just my intuition.