astral-sh/ruff

[`Pylint`] `PLE2510` fix causes syntax error inside pre-3.12 f-strings

Closed

#18,816 opened on Jun 20, 2025

 (4 comments) (0 reactions) (0 assignees)Rust (2,088 forks)batch import
bugfixeshelp wanted

Repository metrics

Stars
 (47,527 stars)
PR merge metrics
 (Avg merge 3d 8h) (573 merged PRs in 30d)

Description

Summary

If a backspace is inside an f-string replacement while a pre-3.12 version is targeted, the fix for invalid-character-backspace (PLE2510) will introduce a syntax error. This happens both inside a string inside the replacement, and inside the format specs. playground

PS D:\python_projects> Get-Content issue.py
f"{'␈'}"

^ note: I'm cheating here, PowerShell does not actually display the backspace character as , it actually gets displayed as f"{'}"

PS D:\python_projects> uvx ruff check issue.py --isolated --select PLE --target-version py39
issue.py:1:5: PLE2510 [*] Invalid unescaped character backspace, use "\b" instead
  |
1 | f"{'␈'}"
  |     ^ PLE2510
  |
  = help: Replace with escape sequence

Found 1 error.
[*] 1 fixable with the `--fix` option.
PS D:\python_projects> uvx ruff check issue.py --isolated --select PLE --target-version py39 --fix
issue.py:1:5: SyntaxError: Cannot use an escape sequence (backslash) in f-strings on Python 3.9 (syntax was added in Python 3.12)
  |
1 | f"{'\b'}"
  |     ^
  |

Found 2 errors (1 fixed, 1 remaining).

This also applies to PLE2512, PLE2513, and PLE2515 playground, as well as PLE2514, but the playground does not support null chars.

Version

ruff 0.12.0 (87f0feb 2025-06-17) + playground

Contributor guide