Improve the error message for PLW0642 (#12866)

This commit is contained in:
Alex Waygood 2024-08-13 17:16:35 +01:00 committed by Micha Reiser
parent 2e211c5c22
commit d8ebb03591
2 changed files with 17 additions and 17 deletions

View file

@ -53,7 +53,7 @@ impl Violation for SelfOrClsAssignment {
let SelfOrClsAssignment { method_type } = self; let SelfOrClsAssignment { method_type } = self;
format!( format!(
"Confusing assignment to `{}` argument in {method_type} method", "Reassigned `{}` variable in {method_type} method",
method_type.arg_name(), method_type.arg_name(),
) )
} }

View file

@ -1,7 +1,7 @@
--- ---
source: crates/ruff_linter/src/rules/pylint/mod.rs source: crates/ruff_linter/src/rules/pylint/mod.rs
--- ---
self_or_cls_assignment.py:4:9: PLW0642 Confusing assignment to `cls` argument in class method self_or_cls_assignment.py:4:9: PLW0642 Reassigned `cls` variable in class method
| |
2 | @classmethod 2 | @classmethod
3 | def list_fruits(cls) -> None: 3 | def list_fruits(cls) -> None:
@ -12,7 +12,7 @@ self_or_cls_assignment.py:4:9: PLW0642 Confusing assignment to `cls` argument in
| |
= help: Consider using a different variable name = help: Consider using a different variable name
self_or_cls_assignment.py:5:9: PLW0642 Confusing assignment to `cls` argument in class method self_or_cls_assignment.py:5:9: PLW0642 Reassigned `cls` variable in class method
| |
3 | def list_fruits(cls) -> None: 3 | def list_fruits(cls) -> None:
4 | cls = "apple" # PLW0642 4 | cls = "apple" # PLW0642
@ -23,7 +23,7 @@ self_or_cls_assignment.py:5:9: PLW0642 Confusing assignment to `cls` argument in
| |
= help: Consider using a different variable name = help: Consider using a different variable name
self_or_cls_assignment.py:6:9: PLW0642 Confusing assignment to `cls` argument in class method self_or_cls_assignment.py:6:9: PLW0642 Reassigned `cls` variable in class method
| |
4 | cls = "apple" # PLW0642 4 | cls = "apple" # PLW0642
5 | cls: Fruit = "apple" # PLW0642 5 | cls: Fruit = "apple" # PLW0642
@ -34,7 +34,7 @@ self_or_cls_assignment.py:6:9: PLW0642 Confusing assignment to `cls` argument in
| |
= help: Consider using a different variable name = help: Consider using a different variable name
self_or_cls_assignment.py:7:10: PLW0642 Confusing assignment to `cls` argument in class method self_or_cls_assignment.py:7:10: PLW0642 Reassigned `cls` variable in class method
| |
5 | cls: Fruit = "apple" # PLW0642 5 | cls: Fruit = "apple" # PLW0642
6 | cls += "orange" # PLW0642 6 | cls += "orange" # PLW0642
@ -45,7 +45,7 @@ self_or_cls_assignment.py:7:10: PLW0642 Confusing assignment to `cls` argument i
| |
= help: Consider using a different variable name = help: Consider using a different variable name
self_or_cls_assignment.py:8:9: PLW0642 Confusing assignment to `cls` argument in class method self_or_cls_assignment.py:8:9: PLW0642 Reassigned `cls` variable in class method
| |
6 | cls += "orange" # PLW0642 6 | cls += "orange" # PLW0642
7 | *cls = "banana" # PLW0642 7 | *cls = "banana" # PLW0642
@ -56,7 +56,7 @@ self_or_cls_assignment.py:8:9: PLW0642 Confusing assignment to `cls` argument in
| |
= help: Consider using a different variable name = help: Consider using a different variable name
self_or_cls_assignment.py:9:16: PLW0642 Confusing assignment to `cls` argument in class method self_or_cls_assignment.py:9:16: PLW0642 Reassigned `cls` variable in class method
| |
7 | *cls = "banana" # PLW0642 7 | *cls = "banana" # PLW0642
8 | cls, blah = "apple", "orange" # PLW0642 8 | cls, blah = "apple", "orange" # PLW0642
@ -66,7 +66,7 @@ self_or_cls_assignment.py:9:16: PLW0642 Confusing assignment to `cls` argument i
| |
= help: Consider using a different variable name = help: Consider using a different variable name
self_or_cls_assignment.py:10:16: PLW0642 Confusing assignment to `cls` argument in class method self_or_cls_assignment.py:10:16: PLW0642 Reassigned `cls` variable in class method
| |
8 | cls, blah = "apple", "orange" # PLW0642 8 | cls, blah = "apple", "orange" # PLW0642
9 | blah, (cls, blah2) = "apple", ("orange", "banana") # PLW0642 9 | blah, (cls, blah2) = "apple", ("orange", "banana") # PLW0642
@ -77,7 +77,7 @@ self_or_cls_assignment.py:10:16: PLW0642 Confusing assignment to `cls` argument
| |
= help: Consider using a different variable name = help: Consider using a different variable name
self_or_cls_assignment.py:14:9: PLW0642 Confusing assignment to `cls` argument in class method self_or_cls_assignment.py:14:9: PLW0642 Reassigned `cls` variable in class method
| |
12 | @classmethod 12 | @classmethod
13 | def add_fruits(cls, fruits, /) -> None: 13 | def add_fruits(cls, fruits, /) -> None:
@ -88,7 +88,7 @@ self_or_cls_assignment.py:14:9: PLW0642 Confusing assignment to `cls` argument i
| |
= help: Consider using a different variable name = help: Consider using a different variable name
self_or_cls_assignment.py:17:9: PLW0642 Confusing assignment to `self` argument in instance method self_or_cls_assignment.py:17:9: PLW0642 Reassigned `self` variable in instance method
| |
16 | def print_color(self) -> None: 16 | def print_color(self) -> None:
17 | self = "red" # PLW0642 17 | self = "red" # PLW0642
@ -98,7 +98,7 @@ self_or_cls_assignment.py:17:9: PLW0642 Confusing assignment to `self` argument
| |
= help: Consider using a different variable name = help: Consider using a different variable name
self_or_cls_assignment.py:18:9: PLW0642 Confusing assignment to `self` argument in instance method self_or_cls_assignment.py:18:9: PLW0642 Reassigned `self` variable in instance method
| |
16 | def print_color(self) -> None: 16 | def print_color(self) -> None:
17 | self = "red" # PLW0642 17 | self = "red" # PLW0642
@ -109,7 +109,7 @@ self_or_cls_assignment.py:18:9: PLW0642 Confusing assignment to `self` argument
| |
= help: Consider using a different variable name = help: Consider using a different variable name
self_or_cls_assignment.py:19:9: PLW0642 Confusing assignment to `self` argument in instance method self_or_cls_assignment.py:19:9: PLW0642 Reassigned `self` variable in instance method
| |
17 | self = "red" # PLW0642 17 | self = "red" # PLW0642
18 | self: Self = "red" # PLW0642 18 | self: Self = "red" # PLW0642
@ -120,7 +120,7 @@ self_or_cls_assignment.py:19:9: PLW0642 Confusing assignment to `self` argument
| |
= help: Consider using a different variable name = help: Consider using a different variable name
self_or_cls_assignment.py:20:10: PLW0642 Confusing assignment to `self` argument in instance method self_or_cls_assignment.py:20:10: PLW0642 Reassigned `self` variable in instance method
| |
18 | self: Self = "red" # PLW0642 18 | self: Self = "red" # PLW0642
19 | self += "blue" # PLW0642 19 | self += "blue" # PLW0642
@ -131,7 +131,7 @@ self_or_cls_assignment.py:20:10: PLW0642 Confusing assignment to `self` argument
| |
= help: Consider using a different variable name = help: Consider using a different variable name
self_or_cls_assignment.py:21:9: PLW0642 Confusing assignment to `self` argument in instance method self_or_cls_assignment.py:21:9: PLW0642 Reassigned `self` variable in instance method
| |
19 | self += "blue" # PLW0642 19 | self += "blue" # PLW0642
20 | *self = "blue" # PLW0642 20 | *self = "blue" # PLW0642
@ -142,7 +142,7 @@ self_or_cls_assignment.py:21:9: PLW0642 Confusing assignment to `self` argument
| |
= help: Consider using a different variable name = help: Consider using a different variable name
self_or_cls_assignment.py:22:16: PLW0642 Confusing assignment to `self` argument in instance method self_or_cls_assignment.py:22:16: PLW0642 Reassigned `self` variable in instance method
| |
20 | *self = "blue" # PLW0642 20 | *self = "blue" # PLW0642
21 | self, blah = "red", "blue" # PLW0642 21 | self, blah = "red", "blue" # PLW0642
@ -152,7 +152,7 @@ self_or_cls_assignment.py:22:16: PLW0642 Confusing assignment to `self` argument
| |
= help: Consider using a different variable name = help: Consider using a different variable name
self_or_cls_assignment.py:23:16: PLW0642 Confusing assignment to `self` argument in instance method self_or_cls_assignment.py:23:16: PLW0642 Reassigned `self` variable in instance method
| |
21 | self, blah = "red", "blue" # PLW0642 21 | self, blah = "red", "blue" # PLW0642
22 | blah, (self, blah2) = "apple", ("orange", "banana") # PLW0642 22 | blah, (self, blah2) = "apple", ("orange", "banana") # PLW0642
@ -163,7 +163,7 @@ self_or_cls_assignment.py:23:16: PLW0642 Confusing assignment to `self` argument
| |
= help: Consider using a different variable name = help: Consider using a different variable name
self_or_cls_assignment.py:26:9: PLW0642 Confusing assignment to `self` argument in instance method self_or_cls_assignment.py:26:9: PLW0642 Reassigned `self` variable in instance method
| |
25 | def print_color(self, color, /) -> None: 25 | def print_color(self, color, /) -> None:
26 | self = color 26 | self = color