astral-sh / astral-sh/ruff

UP032 fix can shadow INT002 violation

Open
#8,693 2 comments 1 reaction 0 assignees View on GitHub
needs-decision
Dominant language
Rust
Stars
49.7k
Forks
2.4k
Avg merge
2d 1h
Merged PRs (30d)
458

Description

### Python file
```py
_('foo {}'.format(bar))
```

### ruff output

```shell
$ ruff --isolated --select INT,UP --preview rufftest/ruff_sample.py
rufftest/ruff_sample.py:1:3: UP032 [*] Use f-string instead of `format` call
rufftest/ruff_sample.py:1:3: INT002 `format` method argument is resolved before function call; consider `_("string %s") % arg`
Found 2 errors.
[*] 1 fixable with the `--fix` option.

$ ruff --isolated --select INT,UP --preview rufftest/ruff_sample.py --diff
--- rufftest/ruff_sample.py
+++ rufftest/ruff_sample.py
@@ -1 +1 @@
-_('foo {}'.format(bar))
+_(f'foo {bar}')

Would fix 1 error.
```

Luckily the fixed version will then trigger INT001, but maybe UP032 could try to detect if it's inside a gettext call and in that case mark the fix as unsafe?

Contributor guide

Open the contributing guide

Research direction

Reproduce the interaction with `ruff --isolated --select INT,UP --preview` using the shown gettext-style example, then compare the normal output and `--diff` behavior. Trace the UP032 rule and its fix handling; done means the proposed fix does not hide the INT002 violation or otherwise changes the reported safety of this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
internationalization, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.