Skip to content

UP032 fix fails when braces are created via escapes #19792

@MeGaGiGaGon

Description

@MeGaGiGaGon

Summary

The fix for f-string (UP032) will fail if the braces ({ and }) are created via escapes instead of literal characters: Example

PS ~>echo '"\x7btest\x7d".format(test=1)' | uvx ruff check --select UP032 --fix -
"\x7btest\x7d"
Found 1 error (1 fixed, 0 remaining).

This does work properly with .format and could be fixed the same way as the non-cursed version:

>>> "\x7btest\x7d".format(test=1)
'1'
>>> f"{1}"
'1'

This also applies to all the other ways of writing { and } non-literally (\x, \u, \U, \N)

Version

ruff 0.12.7 (c5ac998 2025-07-29)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixesRelated to suggested fixes for violations

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions