ruff icon indicating copy to clipboard operation
ruff copied to clipboard

[`pylint`] - implement `self-cls-assignment` (`W0642`)

Open diceroll123 opened this issue 1 year ago • 2 comments
trafficstars

Summary

Implements W0642/self-cls-assignment

See: #970

Test Plan

cargo test

diceroll123 avatar Dec 24 '23 22:12 diceroll123

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

github-actions[bot] avatar Dec 24 '23 22:12 github-actions[bot]

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)

MichaReiser avatar Apr 05 '24 10:04 MichaReiser

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

diceroll123 avatar Apr 13 '24 17:04 diceroll123