[pylint] Implement self-cls-assignment (W0642)#9267
[pylint] Implement self-cls-assignment (W0642)#9267dhruvmanila merged 7 commits intoastral-sh:mainfrom
pylint] Implement self-cls-assignment (W0642)#9267Conversation
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| PLW0642 | 52 | 52 | 0 | 0 | 0 |
W0642/self-cls-assignmentpylint] - implement W0642/self-cls-assignment
318898e to
8fbfbf9
Compare
8fbfbf9 to
aae4512
Compare
pylint] - implement W0642/self-cls-assignmentpylint] - implement self-cls-assignment (W0642)
|
The rule fits into the suspicious category. We should consider renaming the rule to |
dhruvmanila
left a comment
There was a problem hiding this comment.
Thank you for the PR!
This looks like a great start. I've a few recommendations around testing and logic but otherwise looks good.
crates/ruff_linter/src/rules/pylint/rules/self_cls_assignment.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/pylint/rules/self_cls_assignment.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/pylint/rules/self_cls_assignment.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/pylint/rules/self_cls_assignment.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/pylint/rules/self_cls_assignment.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/pylint/rules/self_cls_assignment.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/pylint/rules/self_cls_assignment.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/resources/test/fixtures/pylint/self_cls_assignment.py
Show resolved
Hide resolved
crates/ruff_linter/resources/test/fixtures/pylint/self_cls_assignment.py
Show resolved
Hide resolved
crates/ruff_linter/resources/test/fixtures/pylint/self_cls_assignment.py
Show resolved
Hide resolved
|
Couldn't find any official Python documentation on why this is not a good thing to do in code, but I've added an example, and addressed other changes as well. 😄 |
dhruvmanila
left a comment
There was a problem hiding this comment.
Thank you! I made some additional changes which I've listed down:
- Check starred expressions (
*self = "foo") - Update example case and add "Use instead:" section
Looking at the ecosystem changes, a follow-up would probably be to allow type casting like the following:
self = cast(Fruits, self)
cls = cast(Colors, cls)pylint] - implement self-cls-assignment (W0642)pylint] Implement self-cls-assignment (W0642)
Summary
Implements
W0642/self-cls-assignmentSee: #970
Test Plan
cargo test