Skip to content

Commit a283ef1

Browse files
authored
Remove unnecessary 'invalid_primary' rule in the parser (GH-27186)
1 parent 000e70a commit a283ef1

File tree

4 files changed

+239
-309
lines changed

4 files changed

+239
-309
lines changed

Grammar/python.gram

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,6 @@ await_primary[expr_ty] (memo):
666666
| AWAIT a=primary { CHECK_VERSION(expr_ty, 5, "Await expressions are", _PyAST_Await(a, EXTRA)) }
667667
| primary
668668
primary[expr_ty]:
669-
| invalid_primary # must be before 'primay genexp' because of invalid_genexp
670669
| a=primary '.' b=NAME { _PyAST_Attribute(a, b->v.Name.id, Load, EXTRA) }
671670
| a=primary b=genexp { _PyAST_Call(a, CHECK(asdl_expr_seq*, (asdl_expr_seq*)_PyPegen_singleton_seq(p, b)), NULL, EXTRA) }
672671
| a=primary '(' b=[arguments] ')' {
@@ -893,8 +892,6 @@ invalid_del_stmt:
893892
RAISE_SYNTAX_ERROR_INVALID_TARGET(DEL_TARGETS, a) }
894893
invalid_block:
895894
| NEWLINE !INDENT { RAISE_INDENTATION_ERROR("expected an indented block") }
896-
invalid_primary:
897-
| primary a='{' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "invalid syntax") }
898895
invalid_comprehension:
899896
| ('[' | '(' | '{') a=starred_expression for_if_clauses {
900897
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "iterable unpacking cannot be used in comprehension") }

Lib/test/test_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def testSyntaxErrorOffset(self):
209209
check(b'Python = "\xcf\xb3\xf2\xee\xed" +', 1, 18)
210210
check('x = "a', 1, 5)
211211
check('lambda x: x = 2', 1, 1)
212-
check('f{a + b + c}', 1, 2)
212+
check('f{a + b + c}', 1, 1)
213213
check('[file for str(file) in []\n])', 2, 2)
214214
check('a = « hello » « world »', 1, 5)
215215
check('[\nfile\nfor str(file)\nin\n[]\n]', 3, 5)

Lib/test/test_syntax.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ def test_expression_with_assignment(self):
13051305
)
13061306

13071307
def test_curly_brace_after_primary_raises_immediately(self):
1308-
self._check_error("f{", "invalid syntax", mode="single")
1308+
self._check_error("f{}", "invalid syntax", mode="single")
13091309

13101310
def test_assign_call(self):
13111311
self._check_error("f() = 1", "assign")

0 commit comments

Comments
 (0)