astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
32.85k stars 1.1k forks source link

`UP038` documentation outdated wrt. fix safety #13051

Open VeckoTheGecko opened 2 months ago

VeckoTheGecko commented 2 months ago

Docs mention "Fix is always available." but it is flagged as unsafe in the code

ruff --version
ruff 0.6.1

Code

with isinstance(2, (int,float)) I get

test.py:1:1: UP038 Use `X | Y` in `isinstance` call instead of `(X, Y)`
  |
1 | isinstance(2, (int, float))
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP038
  |
  = help: Convert to `X | Y`

Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).

Related to #2923

MichaReiser commented 2 months ago

Thanks for opening this issue. I can see how this is confusing. I was actually just about to change the rule metadata but then noticed that, maybe I shouldn't.

The documentation's fix availability doesn't consider the fix's safety today, which makes sense because the fix is always available when using --unsafe-fixes. But I can see how this isn't very clear, especially with the CLI message that explicitly states that the fix is unavailable.

@zanieb what's your take on fix availability and fix safety?

VeckoTheGecko commented 2 months ago

I see, so availability != safety (where I assumed it did). If safety was also mentioned in the doc that would have cleared it up (e.g., Fix is always available but not always safe)

dhruvmanila commented 2 months ago

Yeah, I think it might be useful to add some reference to fix safety in the rule header. It might also be useful to either provide a different icon or a different color to the fix icon in the rules table (https://docs.astral.sh/ruff/rules/#legend).