mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:21 +00:00
[pylint
] - Allow __new__
methods to have cls
as their first argument even if decorated with @staticmethod
for bad-staticmethod-argument
(PLW0211
) (#12958)
This commit is contained in:
parent
900e98b584
commit
81a2220ce1
2 changed files with 19 additions and 8 deletions
|
@ -42,3 +42,9 @@ class Foo:
|
||||||
@classmethod
|
@classmethod
|
||||||
def graze(cls, x, y, z):
|
def graze(cls, x, y, z):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Foo:
|
||||||
|
@staticmethod
|
||||||
|
def __new__(cls, x, y, z): # OK, see https://docs.python.org/3/reference/datamodel.html#basic-customization
|
||||||
|
pass
|
||||||
|
|
|
@ -91,13 +91,18 @@ pub(crate) fn bad_staticmethod_argument(
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches!(self_or_cls.name.as_str(), "self" | "cls") {
|
match (name.as_str(), self_or_cls.name.as_str()) {
|
||||||
let diagnostic = Diagnostic::new(
|
("__new__", "cls") => {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
(_, "self" | "cls") => {}
|
||||||
|
_ => return,
|
||||||
|
}
|
||||||
|
|
||||||
|
diagnostics.push(Diagnostic::new(
|
||||||
BadStaticmethodArgument {
|
BadStaticmethodArgument {
|
||||||
argument_name: self_or_cls.name.to_string(),
|
argument_name: self_or_cls.name.to_string(),
|
||||||
},
|
},
|
||||||
self_or_cls.range(),
|
self_or_cls.range(),
|
||||||
);
|
));
|
||||||
diagnostics.push(diagnostic);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue