Skip to content
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

Merged
merged 7 commits into from Apr 15, 2024

Conversation

diceroll123
Copy link
Contributor

Summary

Implements W0642/self-cls-assignment

See: #970

Test Plan

cargo test

Copy link
Contributor

github-actions bot commented Dec 24, 2023

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+52 -0 violations, +0 -0 fixes in 2 projects; 42 projects unchanged)

bokeh/bokeh (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

+ src/bokeh/events.py:182:9: PLW0642 Invalid assignment to `cls` argument in class method

pandas-dev/pandas (+51 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ pandas/core/arrays/categorical.py:568:13: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:1083:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:1098:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:1099:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:1127:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:1136:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:1147:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:1149:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:1154:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:1203:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:1205:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:1221:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:1278:13: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:1292:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:1498:13: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:1717:13: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:2144:17: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:2166:13: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:455:17: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:806:13: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/arrays/datetimelike.py:997:13: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/frame.py:7715:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/frame.py:7728:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/frame.py:8071:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/frame.py:8083:21: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/frame.py:8123:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/generic.py:3407:13: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/generic.py:3568:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/generic.py:7905:17: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/generic.py:7908:17: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/generic.py:7911:17: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/generic.py:9168:13: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/generic.py:9175:17: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/generic.py:9178:17: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/groupby/grouper.py:249:13: PLW0642 Invalid assignment to `cls` argument in class method
+ pandas/core/indexes/base.py:1329:13: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/indexes/base.py:2130:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/indexes/base.py:2913:13: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/indexes/base.py:3061:13: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/indexes/base.py:3293:13: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/indexes/base.py:4384:13: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/indexes/base.py:5958:17: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/indexes/base.py:5962:20: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/internals/blocks.py:1122:13: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/internals/blocks.py:1170:13: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/internals/blocks.py:1733:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/internals/managers.py:578:13: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/series.py:5835:9: PLW0642 Invalid assignment to `self` argument in instance method
+ pandas/core/series.py:5844:9: PLW0642 Invalid assignment to `self` argument in instance method
... 2 additional changes omitted for project

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PLW0642 52 52 0 0 0

@diceroll123 diceroll123 changed the title [pylint] - implement W0642/self-cls-assignment [pylint] - implement W0642/self-cls-assignment Jan 20, 2024
@diceroll123 diceroll123 force-pushed the add-W0642 branch 2 times, most recently from 318898e to 8fbfbf9 Compare January 20, 2024 23:09
@diceroll123 diceroll123 changed the title [pylint] - implement W0642/self-cls-assignment [pylint] - implement self-cls-assignment (W0642) Jan 21, 2024
@MichaReiser MichaReiser added the accepted Ready for implementation label Apr 5, 2024
@MichaReiser
Copy link
Member

The rule fits into the suspicious category. We should consider renaming the rule to self-or-cls-assignments to make it grammatically correct allow(self-or-cls-assignments)

@dhruvmanila dhruvmanila self-assigned this Apr 10, 2024
@dhruvmanila dhruvmanila added the rule Implementing or modifying a lint rule label Apr 10, 2024
Copy link
Member

@dhruvmanila dhruvmanila left a 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.

@diceroll123
Copy link
Contributor Author

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. 😄

Copy link
Member

@dhruvmanila dhruvmanila left a 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)

@dhruvmanila dhruvmanila changed the title [pylint] - implement self-cls-assignment (W0642) [pylint] Implement self-cls-assignment (W0642) Apr 15, 2024
@dhruvmanila dhruvmanila added the preview Related to preview mode features label Apr 15, 2024
@dhruvmanila dhruvmanila enabled auto-merge (squash) April 15, 2024 09:02
@dhruvmanila dhruvmanila merged commit c221035 into astral-sh:main Apr 15, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants