8000 gh-123562: Improve `SyntaxError` message for `case ... as a.b` by sobolevn · Pull Request #123563 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
8000

gh-123562: Improve SyntaxError message for case ... as a.b #123563

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
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Address review
  • Loading branch information
sobolevn committed Sep 2, 2024
commit bd7e806e0ebbbd04c13a002a848dd41045eca03f
2 changes: 1 addition & 1 deletion Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ invalid_as_pattern:
| or_pattern 'as' a="_" { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot use '_' as a target") }
| or_pattern 'as' a=expression {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
a, "cannot use pattern target as %s", _PyPegen_get_expr_name(a)) }
a, "cannot use %s as pattern target", _PyPegen_get_expr_name(a)) }
invalid_class_pattern:
| name_or_attr '(' a=invalid_class_argument_pattern { RAISE_SYNTAX_ERROR_KNOWN_RANGE(
PyPegen_first_item(a, pattern_ty),
Expand Down
12 changes: 6 additions & 6 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -1932,31 +1932,31 @@
... case 42 as 1+2+4:
... ...
Traceback (most recent call last):
SyntaxError: cannot use pattern target as expression
SyntaxError: cannot use expression as pattern target

>>> match ...:
... case 42 as a.b:
... ...
Traceback (most recent call last):
SyntaxError: cannot use pattern target as attribute
SyntaxError: cannot use attribute as pattern target

>>> match ...:
... case 42 as (a, b):
... ...
Traceback (most recent call last):
SyntaxError: cannot use pattern target as tuple
SyntaxError: cannot use tuple as pattern target

>>> match ...:
... case 42 as (a + 1):
... ...
Traceback (most recent call last):
SyntaxError: cannot use pattern target as expression
SyntaxError: cannot use expression as pattern target

>>> match ...:
... case (32 as x) | (42 as a()):
... ...
Traceback (most recent call last):
SyntaxError: cannot use pattern target as function call
SyntaxError: cannot use function call as pattern target

>>> match ...:
... case Foo(z=1, y=2, x):
Expand Down Expand Up @@ -2850,7 +2850,7 @@ def test_match_stmt_invalid_as_expr(self):
...
"""
),
errtext="cannot use pattern target as attribute",
errtext="cannot use attribute as pattern target",
lineno=3,
end_lineno=3,
offset=15,
Expand Down
2 changes: 1 addition & 1 deletion Parser/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
0