-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
coreRelated to core functionalityRelated to core functionalityparserRelated to the parserRelated to the parserpython312Related to Python 3.12Related to Python 3.12
Description
PEP 701 formalizes the grammar for f-strings. This will require updates to both the lexer and parser while keeping the AST representation the same.
-
Update the lexer to emit the new tokens (
FSTRING_START,FSTRING_MIDDLE,FSTRING_END). This means thatf"foo {bar}"wouldn't be emitted as a singleStringtoken but rather something like:FSTRING_START('f"') FSTRING_MIDDLE("foo ") LBRACE NAME("bar") RBRACE FSTRING_END('f"') -
Update the parser to account for any grammar changes required to recognize these tokens and parse it into an equivalent AST nodes. There are few things to note here:
- We can remove the f-string parsing done in the string parser (
string.rs) - Debug expressions (
f"foo {bar = }") preserves whitespaces using thedebug_textfield. Newlines needs to be preserved as well. - Implicit string concatenation
SimpleTokenizerchanges
- We can remove the f-string parsing done in the string parser (
The goal is to complete this in the current iteration (August) before the official release of Python 3.12.
Tasks
- Add support for PEP 701 in the lexer #7042
- Add support for PEP 701 in the parser #7043
- Split/Remove Backward tokenization #6363
- PEP 701 linter changes #7299
- Update
FormatStringContinuationto use the new f-string tokens #7517
Reference implementation:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
coreRelated to core functionalityRelated to core functionalityparserRelated to the parserRelated to the parserpython312Related to Python 3.12Related to Python 3.12