Skip to content

Commit d8a1072

Browse files
authored
pythongh-153568: Reduce parser allocations (python#157374)
1 parent 9cc3547 commit d8a1072

8 files changed

Lines changed: 905 additions & 845 deletions

File tree

Grammar/python.gram

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,8 +1181,12 @@ invalid_arguments:
11811181
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, _PyPegen_get_last_comprehension_item(PyPegen_last_item(b, comprehension_ty)), "Generator expression must be parenthesized") }
11821182
| a=args ',' args { _PyPegen_arguments_parsing_error(p, a) }
11831183
invalid_kwarg:
1184-
| a[Token*]=('True'|'False'|'None') b='=' {
1185-
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot assign to %s", PyBytes_AS_STRING(a->bytes)) }
1184+
| a='True' b='=' {
1185+
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot assign to True") }
1186+
| a='False' b='=' {
1187+
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot assign to False") }
1188+
| a='None' b='=' {
1189+
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot assign to None") }
11861190
| a=NAME b='=' expression for_if_clauses {
11871191
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '==' or ':=' instead of '='?")}
11881192
| !(NAME '=') a=expression b='=' {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reduce temporary allocations while parsing Python source.

0 commit comments

Comments
 (0)