ruff/crates
Alex Waygood 22728808aa
[`pyupgrade`] Ensure we do not rename two type parameters to the same name (`UP049`) (#16038)
Fixes #16024

## Summary

This PR adds proper isolation for `UP049` fixes so that two type
parameters are not renamed to the same name, which would introduce
invalid syntax. E.g. for this:

```py
class Foo[_T, __T]: ...
```

we cannot apply two autofixes to the class, as that would produce
invalid syntax -- this:

```py
class Foo[T, T]: ...
```

The "isolation" here means that Ruff won't apply more than one fix to
the same type-parameter list in a single iteration of the loop it does
to apply all autofixes. This means that after the first autofix has been
done, the semantic model will have recalculated which variables are
available in the scope, meaning that the diagnostic for the second
parameter will be deemed unfixable since it collides with an existing
name in the same scope (the name we autofixed the first parameter to in
an earlier iteration of the autofix loop).

Cc. @ntBre, for interest!

## Test Plan

I added an integration test that reproduces the bug on `main`.
2025-02-08 15:44:04 +00:00
..
red_knot [red-knot] fix unresolvable import range (#15976) 2025-02-05 14:01:58 -05:00
red_knot_project Add knot.toml schema (#15735) 2025-02-07 10:59:40 +01:00
red_knot_python_semantic [red-knot] Unpacker: Make invariant explicit and directly return a Type (#16018) 2025-02-07 12:00:04 +00:00
red_knot_server [red-knot] Make `Diagnostic::file` optional (#15640) 2025-01-23 10:43:14 +01:00
red_knot_test [red-knot] Fixup a couple of nits in the `red_knot_test` README (#15996) 2025-02-06 15:04:27 +00:00
red_knot_vendored Sync vendored typeshed stubs (#15864) 2025-02-01 01:01:58 +00:00
red_knot_wasm Update Rust crate rand to 0.9.0 (#15899) 2025-02-03 12:25:57 +01:00
ruff [`pyupgrade`] Ensure we do not rename two type parameters to the same name (`UP049`) (#16038) 2025-02-08 15:44:04 +00:00
ruff_annotate_snippets Fix docstring in ruff_annotate_snippets (#15748) 2025-01-26 22:25:29 -05:00
ruff_benchmark Vendor benchmark test files (#15878) 2025-02-02 18:16:07 +00:00
ruff_cache Fix cache key collisions for paths with separators (#12159) 2024-07-03 07:36:46 -05:00
ruff_db Add knot.toml schema (#15735) 2025-02-07 10:59:40 +01:00
ruff_dev Add knot.toml schema (#15735) 2025-02-07 10:59:40 +01:00
ruff_diagnostics Show errors for attempted fixes only when passed `--verbose` (#15237) 2025-01-03 08:50:13 -06:00
ruff_formatter Upgrade Rust toolchain to 1.84.0 (#15408) 2025-01-11 09:51:58 +01:00
ruff_graph Add support for configuring knot in `pyproject.toml` files (#15493) 2025-01-17 09:41:06 +01:00
ruff_index [red-knot] small efficiency improvements and bugfixes to use-def map building (#12373) 2024-07-18 09:24:58 -07:00
ruff_linter [`pyupgrade`] Ensure we do not rename two type parameters to the same name (`UP049`) (#16038) 2025-02-08 15:44:04 +00:00
ruff_macros Add knot.toml schema (#15735) 2025-02-07 10:59:40 +01:00
ruff_notebook Update Rust crate rand to 0.9.0 (#15899) 2025-02-03 12:25:57 +01:00
ruff_python_ast [`flake8-annotations`] Correct syntax for `typing.Union` in suggested return type fixes for `ANN20x` rules (#16025) 2025-02-07 17:17:20 -06:00
ruff_python_ast_integration_tests Update insta snapshots (#14366) 2024-11-15 19:31:15 +01:00
ruff_python_codegen Preserve triple quotes and prefixes for strings (#15818) 2025-02-04 08:41:06 -05:00
ruff_python_formatter Workaround Even Better TOML crash related to `allOf` (#15992) 2025-02-06 16:00:50 +01:00
ruff_python_index Extract `LineIndex` independent methods from `Locator` (#13938) 2024-10-28 07:53:41 +00:00
ruff_python_literal Preserve triple quotes and prefixes for strings (#15818) 2025-02-04 08:41:06 -05:00
ruff_python_parser Simplify the `StringFlags` trait (#15944) 2025-02-04 18:14:28 +00:00
ruff_python_resolver Update insta snapshots (#14366) 2024-11-15 19:31:15 +01:00
ruff_python_semantic [flake8-simplify] Only trigger SIM401 on known dictionaries (SIM401) (#15995) 2025-02-07 08:25:20 +00:00
ruff_python_stdlib Revert "Add all PEP-585 names to UP006 rule" (#15250) 2025-01-04 12:23:53 +01:00
ruff_python_trivia [red-knot] Hand-written MDTest parser (#15926) 2025-02-04 14:01:53 +01:00
ruff_python_trivia_integration_tests Update insta snapshots (#14366) 2024-11-15 19:31:15 +01:00
ruff_server Consider `unsafe-fixes` settings for code actions (#15666) 2025-01-22 13:44:13 +05:30
ruff_source_file [`pyupgrade`] Do not report when a UTF-8 comment is followed by a non-UTF-8 one (`UP009`) (#14728) 2024-12-11 10:30:41 +00:00
ruff_text_size [`ruff`] `itertools.starmap(..., zip(...))` (`RUF058`) (#15483) 2025-01-16 15:18:12 +01:00
ruff_wasm Bump version to 0.9.5 (#16002) 2025-02-06 13:24:45 -06:00
ruff_workspace Config error only when `flake8-import-conventions` alias conflicts with `isort.required-imports` bound name (#15918) 2025-02-04 17:05:35 -06:00