-
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
Refactor method classification logic: __new__
methods are now classified as staticmethod
#13305
base: main
Are you sure you want to change the base?
Refactor method classification logic: __new__
methods are now classified as staticmethod
#13305
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLW0642 | 2 | 0 | 2 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+0 -2 violations, +0 -0 fixes in 1 projects; 53 projects unchanged)
pandas-dev/pandas (+0 -2 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
- pandas/core/groupby/grouper.py:258:13: PLW0642 Reassigned `cls` variable in class method - pandas/io/excel/_base.py:1178:13: PLW0642 Reassigned `cls` variable in class method
Changes by rule (1 rules affected)
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLW0642 | 2 | 0 | 2 | 0 | 0 |
I'm sure there are other breaking changes besides the ruff-ecosystem results |
Affected Rules
ARG003, ARG004ARG003 ( PLW0642
N804, PLW0211N804 ( PLR0913, PLR0917PLR0913 ( ExampleYou can view an example of how these rules are applied here: class ClassDunderNew:
@classmethod
def __new__(
cls,
x, # ARG003: Unused class method argument: `x`
):
cls = 1 # PLW0642: Reassigned `cls` variable in class method
@classmethod
def __new__( # PLR0913: Too many arguments in function definition (6 > 5) # PLR0917: Too many positional arguments (6/5)
self, # N804: First argument of a class method should be named `cls`
a1, a2, a3, a4, a5,
a6,
):
...
class StaticDunderNew:
@staticmethod
def __new__(
cls,
x, # ARG004: Unused static method argument: `x`
):
cls = 1
@staticmethod
def __new__( # PLR0913: Too many arguments in function definition (6 > 5) # PLR0917: Too many positional arguments (6/5)
self, # PLW0211: First argument of a static method should not be named `self`
a1, a2, a3, a4, a5,
):
... |
I reviewed all the code affected by Please check if these affected rules are acceptable. :) |
Summary
__new__
methods are technically static methods, withcls
as their first argument. However, Ruff currently classifies them as classmethod, which causes two issues:__new__
is explicitly treated as a classmethod.Based on #13154, I have excluded the first argument
cls
of__new__
from ARG004. (not concluded, it can be change)Closes #13154