From 6a2f12a754d6be016c8abda5f8d432795574b594 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 22 Oct 2024 13:41:51 +0200 Subject: [PATCH] [3.10] gh-125529: Avoid f-strings in the metagrammar (#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 --- Tools/peg_generator/pegen/grammar_parser.py | 2 +- Tools/peg_generator/pegen/metagrammar.gram | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tools/peg_generator/pegen/grammar_parser.py b/Tools/peg_generator/pegen/grammar_parser.py index 892df5cf8ccca1..de735649d46159 100644 --- a/Tools/peg_generator/pegen/grammar_parser.py +++ b/Tools/peg_generator/pegen/grammar_parser.py @@ -420,7 +420,7 @@ def named_item(self) -> Optional[NamedItem]: and (item := self.item()) ): - return NamedItem ( name . string , item , f"{type.string}*" ) + return NamedItem ( name . string , item , type . string + "*" ) self.reset(mark) if cut: return None cut = False diff --git a/Tools/peg_generator/pegen/metagrammar.gram b/Tools/peg_generator/pegen/metagrammar.gram index bb4355fd189e05..77695d5e0a91a0 100644 --- a/Tools/peg_generator/pegen/metagrammar.gram +++ b/Tools/peg_generator/pegen/metagrammar.gram @@ -84,7 +84,7 @@ items[NamedItemList]: | named_item { [named_item] } named_item[NamedItem]: - | NAME '[' type=NAME '*' ']' '=' ~ item {NamedItem(name.string, item, f"{type.string}*")} + | NAME '[' type=NAME '*' ']' '=' ~ item {NamedItem(name.string, item, type.string+"*")} | NAME '[' type=NAME ']' '=' ~ item {NamedItem(name.string, item, type.string)} | NAME '=' ~ item {NamedItem(name.string, item)} | item {NamedItem(None, item)}