A method has no parameter to receive the instance or class
What it finds
def reset(): in a class body: calling a method through an instance passes the instance as the first argument, and through the class in a classmethod the class. A method without any parameter that can take it raises TypeError on every such call. @staticmethod is what makes a function in a class take no instance.
Methods with any decorator are left alone, since a decorator can change how the function is called. The rule is in the recommended tier because a class can also be used as a namespace whose functions are only ever called through the class.
From the rule's source, method_without_self.rs.
class Counter: def reset():tx0 reports: the method reset has no parameter for the instance, so calling it raises TypeError return 0 def keyed(*, key):tx0 reports: the method keyed has no parameter return key @staticmethod def make(): return Counter() def flexible(*args): return args def normal(self): return self def helper(): return 1 Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/python:method-without-self" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:method-without-self] reason="..."tx0 explain tx0/python:method-without-self shows the same in the terminal. Found a false positive? Report it.