Skip to content

UP032 fix misinterprets \N in a raw string as an escape sequence #22060

@dscorbett

Description

@dscorbett

Summary

The fix for f-string (UP032) can introduce a runtime error by misinterpreting \N in a raw string literal, where it is not an escape sequence. The fix in #21901 should not apply to raw strings. Example:

$ cat >up032.py <<'# EOF'
print(r"\N{angle}AOB = {angle}°".format(angle=180))
# EOF

$ python up032.py
\N180AOB = 180°

$ ruff --isolated check up032.py --select UP032 --fix
Found 1 error (1 fixed, 0 remaining).

$ cat up032.py
print(rf"\N{angle}AOB = {180}°")

$ python up032.py 2>&1 | tail -n 1
NameError: name 'angle' is not defined. Did you mean: 'range'?

Version

ruff 0.14.10 (45bbb4c 2025-12-18)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixesRelated to suggested fixes for violationshelp wantedContributions especially welcome

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions