Skip to content

Comments

Fixes UP032 crash with raw strings containing \N{#23422

Closed
IMaloney wants to merge 1 commit intoastral-sh:mainfrom
IMaloney:fix-up032-raw-string-backslash-n
Closed

Fixes UP032 crash with raw strings containing \N{#23422
IMaloney wants to merge 1 commit intoastral-sh:mainfrom
IMaloney:fix-up032-raw-string-backslash-n

Conversation

@IMaloney
Copy link

Fixes UP032 crash with raw strings containing \\N{ (#22060)

Here we are converting raw strings like r"\\N{angle}".format(angle=180) to f-strings. Converting to rf"\\N{angle}" makes the f-string try to evaluate {angle} as a variable instead of keeping it as format syntax, which causes NameError.

Let's add a check to skip conversion when raw strings contain \\N{ patterns.

Test Plan

Manual testing with the exact code from the issue:

# Before (crashes after ruff fix):
print(r"\\N{angle}AOB = {angle}°".format(angle=180))

# After (left unchanged, works correctly):
print(r"\\N{angle}AOB = {angle}°".format(angle=180))
# Output: \\N180AOB = 180°

Added test case to UP032_0.py fixture file.

Skip conversion when raw strings contain \N{ patterns.
In raw strings \N is literal, but f-strings evaluate {name} as a variable,
causing NameError.

Fixes astral-sh#22060
@ntBre
Copy link
Contributor

ntBre commented Feb 19, 2026

Thanks for working on this, but it looks like there's already an open PR for this issue: #22149. So I'll close this for now.

@ntBre ntBre closed this Feb 19, 2026
@IMaloney IMaloney deleted the fix-up032-raw-string-backslash-n branch February 20, 2026 19:41
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.

2 participants