Repository navigation
Fix f-string replacement braces following backslashes - #256
Closed
Sarbajit-Sengupta wants to merge 1 commit into
Closed
Sarbajit-Sengupta wants to merge 1 commit into
Sarbajit-Sengupta wants to merge 1 commit 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.
Fixes #207.
Parso's f-string literal scanner consumes a backslash followed by a brace as one escape. Python does not use backslashes to escape replacement-field braces. This rejects valid raw f-strings such as
rf"\{value:0>3o}"and accepts an otherwise unmatched closing brace inrf"\}".Keep the literal backslash in the string token and leave the following brace for the normal field parser, in both single-line and multiline strings. Regression cases cover raw prefix order/case, all four quote styles, one/two/three backslashes, source round trips, name references and rejection of unmatched closing braces. CPython's AST parser verifies the test inputs' validity.
Validation on Windows / Python 3.13.5: 36 new cases fail and 16 controls pass before the change; all 2,040 tests pass after it. Flake8 passes using CI's F401 exception. Zuban over the source and new test reports one existing diagnostic at unchanged
parso/utils.py:95; its unrestricted Windows run also checks invalid-syntax fixtures despite the configured slash-based exclusion. No diagnostic was reported in either changed Python file. Other Python versions have not been run locally.