Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[3.10] gh-125529: Avoid f-strings in the metagrammar
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: Petr Viktorin <encukou@gmail.com>
  • Loading branch information
lysnikolaou and encukou committed Oct 16, 2024
commit 697a0776c3486af4541407925c455e39521d5b8f
2 changes: 1 addition & 1 deletion Tools/peg_generator/pegen/grammar_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Tools/peg_generator/pegen/metagrammar.gram
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down