Skip to content

Accept backslashes before f-string replacement fields - #253

Closed
rupayon123 wants to merge 1 commit into
davidhalter:masterfrom
rupayon123:fix/raw-fstring-backslash-207
Closed

rupayon123 wants to merge 1 commit into
davidhalter:masterfrom
rupayon123:fix/raw-fstring-backslash-207

Conversation

@rupayon123

Copy link
Copy Markdown

Backslashes before braces in f-string literal text were being consumed together with the brace. This rejects valid replacement fields such as rf"\{value}", including the example in #207.

Keep the backslash as literal text and let the normal brace rules handle replacement fields and doubled braces. Named Unicode escapes and other escapes retain their existing branches. Both single-line and triple-quoted f-strings use the corrected rule.

Regression coverage includes ordinary/raw f-strings, format specifications, doubled braces, the original nested-call example, and rejection of a backslash followed by an unmatched closing brace. The 109 valid-input cases failed before the fix.

Validation on Python 3.12.13:

  • Full suite: python -m pytest -q — 2,102 passed.
  • CI Flake8 command passed.
  • zuban check --python-executable ../parso/.venv/bin/python — no issues in 49 files. The explicit interpreter selects the shared test environment for this worktree.
  • git diff --check passed.

Local grammar coverage spans 3.6–3.14; the GitHub runtime matrix has not run yet.

Fixes #207.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KeyError: ReservedString(})

2 participants