Skip to content

Commit 6a2f12a

Browse files
encukoulysnikolaou
andauthored
[3.10] pythongh-125529: Avoid f-strings in the metagrammar (python#125582)
Grammar actions need to be valid Python tokens and the accepted tokens need to be listed in the actions mini-grammar). In Python 3.12+ (PEP 701), f-strings are no longer STRING tokens, so pegen fails to regenerate the metaparser on this Python version, as in: PYTHON_FOR_REGEN=python3.12 make regen-pegen-metaparser Use `+` and plain strings rather than f-strings. Co-authored-by: Lysandros Nikolaou <[email protected]>
1 parent 3c63d80 commit 6a2f12a

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Tools/peg_generator/pegen/grammar_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def named_item(self) -> Optional[NamedItem]:
420420
and
421421
(item := self.item())
422422
):
423-
return NamedItem ( name . string , item , f"{type.string}*" )
423+
return NamedItem ( name . string , item , type . string + "*" )
424424
self.reset(mark)
425425
if cut: return None
426426
cut = False

Tools/peg_generator/pegen/metagrammar.gram

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ items[NamedItemList]:
8484
| named_item { [named_item] }
8585

8686
named_item[NamedItem]:
87-
| NAME '[' type=NAME '*' ']' '=' ~ item {NamedItem(name.string, item, f"{type.string}*")}
87+
| NAME '[' type=NAME '*' ']' '=' ~ item {NamedItem(name.string, item, type.string+"*")}
8888
| NAME '[' type=NAME ']' '=' ~ item {NamedItem(name.string, item, type.string)}
8989
| NAME '=' ~ item {NamedItem(name.string, item)}
9090
| item {NamedItem(None, item)}

0 commit comments

Comments
 (0)