diff --git a/crates/ruff/resources/test/fixtures/pep8_naming/N804.py b/crates/ruff/resources/test/fixtures/pep8_naming/N804.py index eb2859ca97..6ca9a649e1 100644 --- a/crates/ruff/resources/test/fixtures/pep8_naming/N804.py +++ b/crates/ruff/resources/test/fixtures/pep8_naming/N804.py @@ -46,6 +46,10 @@ class MetaClass(ABCMeta): def good_method(cls): pass + @staticmethod + def static_method(not_cls) -> bool: + return False + def func(x): return x diff --git a/crates/ruff/src/ast/function_type.rs b/crates/ruff/src/ast/function_type.rs index 00472d4998..838dac867f 100644 --- a/crates/ruff/src/ast/function_type.rs +++ b/crates/ruff/src/ast/function_type.rs @@ -26,8 +26,18 @@ pub fn classify( let ScopeKind::Class(scope) = &scope.kind else { return FunctionType::Function; }; - // Special-case class method, like `__new__`. - if CLASS_METHODS.contains(&name) + if decorator_list.iter().any(|expr| { + // The method is decorated with a static method decorator (like + // `@staticmethod`). + checker.resolve_call_path(expr).map_or(false, |call_path| { + staticmethod_decorators + .iter() + .any(|decorator| call_path == to_call_path(decorator)) + }) + }) { + FunctionType::StaticMethod + } else if CLASS_METHODS.contains(&name) + // Special-case class method, like `__new__`. || scope.bases.iter().any(|expr| { // The class itself extends a known metaclass, so all methods are class methods. checker.resolve_call_path(expr).map_or(false, |call_path| { @@ -46,16 +56,6 @@ pub fn classify( }) { FunctionType::ClassMethod - } else if decorator_list.iter().any(|expr| { - // The method is decorated with a static method decorator (like - // `@staticmethod`). - checker.resolve_call_path(expr).map_or(false, |call_path| { - staticmethod_decorators - .iter() - .any(|decorator| call_path == to_call_path(decorator)) - }) - }) { - FunctionType::StaticMethod } else { // It's an instance method. FunctionType::Method