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
|
||||
def graze(cls, x, y, z):
|
||||
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;
|
||||
};
|
||||
|
||||
if matches!(self_or_cls.name.as_str(), "self" | "cls") {
|
||||
let diagnostic = Diagnostic::new(
|
||||
match (name.as_str(), self_or_cls.name.as_str()) {
|
||||
("__new__", "cls") => {
|
||||
return;
|
||||
}
|
||||
(_, "self" | "cls") => {}
|
||||
_ => return,
|
||||
}
|
||||
|
||||
diagnostics.push(Diagnostic::new(
|
||||
BadStaticmethodArgument {
|
||||
argument_name: self_or_cls.name.to_string(),
|
||||
},
|
||||
self_or_cls.range(),
|
||||
);
|
||||
diagnostics.push(diagnostic);
|
||||
}
|
||||
));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue