-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pylint
] Implement self-cls-assignment
(W0642
)
#9267
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLW0642 | 52 | 52 | 0 | 0 | 0 |
W0642
/self-cls-assignment
pylint
] - implement W0642
/self-cls-assignment
318898e
to
8fbfbf9
Compare
8fbfbf9
to
aae4512
Compare
pylint
] - implement W0642
/self-cls-assignment
pylint
] - implement self-cls-assignment
(W0642
)
The rule fits into the suspicious category. We should consider renaming the rule to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Outdated
Show resolved
Hide resolved
crates/ruff_linter/resources/test/fixtures/pylint/self_cls_assignment.py
Outdated
Show resolved
Hide resolved
crates/ruff_linter/resources/test/fixtures/pylint/self_cls_assignment.py
Outdated
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. 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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-assignment
See: #970
Test Plan
cargo test