Repository navigation
fix(tokenize): keep a backslash from swallowing an f-string field - #251
Closed
Cherith1222 wants to merge 2 commits into
Closed
Cherith1222 wants to merge 2 commits into
Cherith1222 wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
rf"\{foobar:>3o}"is valid Python. It evaluates to a backslash plus the formatted value. parso treated that backslash as escaping the brace, soparse(..., error_recovery=False)raisedParserSyntaxErroron the closing brace.What changed
{without consuming the brace.\N{SNOWMAN}and a failed name such as\N{ BULLET }stay on the old path.Scope
Tradeoffs
A bare backslash alternative also matched a failed
\Nescape and madef"\N{ BULLET }"parse. The pattern uses a lookahead so the extra match applies only when{is next.Blast Radius
Callers that parse f-strings, including Jedi, now accept this form instead of reporting a syntax error. The existing escape and invalid-name tests still pass.
Verification
test_valid[rf"\\{foobar:>3o}"]failed withParserSyntaxErroron}at column 15.py -3.13 -m pytest -qreported 1993 passed.get_code()returns the same source.Fixes #207
Drafted with Cursor.