[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:
Steve C 2024-08-18 11:30:22 -04:00 committed by GitHub
parent 900e98b584
commit 81a2220ce1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 8 deletions

View file

@ -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

View file

@ -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);
}
));
}