astral-sh/ruff

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

クローズ

#18,816 opened on 2025/06/20

 (4 件のコメント) (0 件のリアクション) (0 人の担当者)Rust (2,088 件のフォーク)batch import
bugfixeshelp wanted

Repository metrics

Stars
 (47,527 個のスター)
PR merge metrics
 (平均マージ 3d 8h) (30d で 573 merged PRs)

説明

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

コントリビューターガイド