summaryrefslogtreecommitdiffstats
path: root/Grammar
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2021-06-24 15:09:57 (GMT)
committerGitHub <noreply@github.com>2021-06-24 15:09:57 (GMT)
commit0acc258fe6f0ec200ca2f6f9294adbf52a244802 (patch)
treecf584ea88a0cbe1c7518fe7436ad3521335b7554 /Grammar
parentb19f45533942e4ad7ddf9d2d94f8b87c6f746bce (diff)
downloadcpython-0acc258fe6f0ec200ca2f6f9294adbf52a244802.zip
cpython-0acc258fe6f0ec200ca2f6f9294adbf52a244802.tar.gz
cpython-0acc258fe6f0ec200ca2f6f9294adbf52a244802.tar.bz2
bpo-44456: Improve the syntax error when mixing keyword and positional patterns (GH-26793)
Diffstat (limited to 'Grammar')
-rw-r--r--Grammar/python.gram8
1 files changed, 8 insertions, 0 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram
index 56daca0..6b2fa6a 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -380,6 +380,7 @@ class_pattern[pattern_ty]:
CHECK(asdl_expr_seq*, _PyPegen_get_pattern_keys(p, keywords)))),
CHECK(asdl_pattern_seq*, _PyPegen_get_patterns(p, keywords)),
EXTRA) }
+ | invalid_class_pattern
positional_patterns[asdl_pattern_seq*]:
| args[asdl_pattern_seq*]=','.pattern+ { args }
keyword_patterns[asdl_seq*]:
@@ -978,6 +979,13 @@ invalid_case_block:
invalid_as_pattern:
| or_pattern 'as' a="_" { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot use '_' as a target") }
| or_pattern 'as' !NAME a=expression { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "invalid pattern target") }
+invalid_class_pattern:
+ | name_or_attr '(' a=invalid_class_argument_pattern { RAISE_SYNTAX_ERROR_KNOWN_RANGE(
+ PyPegen_first_item(a, pattern_ty),
+ PyPegen_last_item(a, pattern_ty),
+ "positional patterns follow keyword patterns") }
+invalid_class_argument_pattern[asdl_pattern_seq*]:
+ | [positional_patterns ','] keyword_patterns ',' a=positional_patterns { a }
invalid_if_stmt:
| 'if' named_expression NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
| a='if' a=named_expression ':' NEWLINE !INDENT {