Skip to content

PY-CLAS0008 · direct_method_descriptor_call_count

Count staticmethod and classmethod calls used without decorator syntax.

This is a deterministic rule for python. Read its implementation.

Parse one Python source file and count direct calls to the built-in staticmethod or classmethod descriptor constructors. This includes their explicit builtins forms. Method binding policy should be visible next to the method declaration through @staticmethod or @classmethod, not reconstructed through assignment or a class-body alias.

Each finding identifies the complete call range and the descriptor constructor that was invoked. A bare decorator is an AST decorator name rather than a call, so normal decorator syntax cannot trigger this rule. The value is the number of direct descriptor constructor calls.

Python permits direct descriptor construction, so this is an explicit readability policy rather than a language error. Calls through dynamic aliases are not guessed. Projects that intentionally build descriptors or metaclasses dynamically can disable this rule for that narrow source boundary.

class Parser:
parse = staticmethod(parse)
wrapped = classmethod(build)
class Parser:
@staticmethod
def parse(text: str) -> "Parser":
return Parser(text)
@classmethod
def build(cls, text: str) -> "Parser":
return cls(text)