[ruff
] Teach autofix for used-dummy-variable
about TypeVars etc. (RUF052
)
#14819
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
For some bindings, such as assignments where the right-hand-side is a
TypeVar
constructor call, renaming the binding can result in invalid code. For example, this diff thatrenamer.rs
might make would take code that mypy (or any other spec-compliant type checker) would have accepted, and turns it into something a type checker will reject:This is because the first argument to the
TypeVar
constructor must be the same as the variable the typevar is being bound to. Detecting this issue in general is impossible (there are lots of classes where this pattern is required), but it seems reasonable to special-case several standard-library classes where this pattern is required.Fixes #14798
Test Plan
Added some more fixtures to RUF052 to check that the new logic in
renamer.rs
works as expected.