[ruff] Mark autofix for RUF052 as always unsafe#14824
Conversation
dylwil3
left a comment
There was a problem hiding this comment.
Seems like the safest thing to do!
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| RUF052 | 1068 | 66 | 0 | 0 | 1002 |
|
Thanks @dylwil3! I just pushed some docs to try to explain why it's marked as unsafe; could you take a quick second look? |
f52633b to
ad5c998
Compare
dylwil3
left a comment
There was a problem hiding this comment.
Looks good! Suggested possible rewording, but it's also fine as is
| /// As well as renaming the variable itself, the fix iterates through all references to the | ||
| /// variable and adapts them to become references to the renamed variable. However, some renamings |
There was a problem hiding this comment.
How about:
- /// As well as renaming the variable itself, the fix iterates through all references to the
- /// variable and adapts them to become references to the renamed variable. However, some renamings
+ /// Ruff will attempt to rename the variable and all references to it. However, some renamingsThere was a problem hiding this comment.
Hmm... I like the improved concision... but I'm not sure about talking about "renaming references". I feel like, strictly speaking, the binding is renamed, but the references do not have a "name" as such (so they cannot be renamed), they only point to (refer) to a name.
I'll push something that's more concise than what I've got currently, though ;)
Thanks!
* main: [`airflow`] Add fix to remove deprecated keyword arguments (`AIR302`) (#14887) Improve mdtests style (#14884) Reference `suppress-dummy-regex-options` in documentation of rules supporting it (#14888) [`flake8-bugbear`] `itertools.batched()` without explicit `strict` (`B911`) (#14408) [`ruff`] Mark autofix for `RUF052` as always unsafe (#14824) [red-knot] Improve type inference for except handlers (#14838) More typos found by codespell (#14880) [red-knot] move standalone expression_ty to TypeInferenceBuilder::file_expression_ty (#14879) [`ruff`] Do not simplify `round()` calls (`RUF046`) (#14832) Stop referring to early ruff versions (#14862) Fix a typo in `class.rs` (#14877) [`flake8-pyi`] Also remove `self` and `cls`'s annotation (`PYI034`) (#14801) [`pyupgrade`] Remove unreachable code in `UP015` implementation (#14871) [`flake8-bugbear`] Skip `B028` if `warnings.warn` is called with `*args` or `**kwargs` (#14870)
Summary
#14819 improved the autofix offered by this rule for a bunch of standard-library classes that must be instantiated according to the pattern
T = TypeVar("T"), where the string literal passed to the constructor must match the name of the variable the call is being assigned to. However, there may be examples of this pattern in third-party libraries that we don't know about, so we can't assume that this fix is now safe.TODO: needs a comment in
crates/ruff_linter/src/rules/ruff/rules/used_dummy_variable.rsabout why it's marked as unsafeTest Plan
cargo test -p ruff_linter