astral-sh / astral-sh/ruff

`UP032` fix fails when braces are created via escapes

Open
#19,792 8 comments 0 reactions 1 assignee View on GitHub

@IDrokin117 is already working on this.

Since Aug 8, 2025.

bug fixes
Dominant language
Rust
Stars
49.7k
Forks
2.4k
Avg merge
2d 1h
Merged PRs (30d)
458

Description

### Summary

The fix for [f-string (UP032)](https://docs.astral.sh/ruff/rules/f-string/#f-string-up032) will fail if the braces (`{` and `}`) are created via escapes instead of literal characters: [Example](https://play.ruff.rs/2a2c4778-a9ff-4499-b9cf-b89c38a25d4b)
```powershell
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:
```pycon
>>> "\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 (c5ac99889 2025-07-29)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.