But no extraneous cognitive noise? By definition, methods appear inside
a class definition, and then I have to process the @staticmethod
decorator. Effectively, the decorator "cancels" the class method status
of the function. I can accomplish the same thing with clean
module-level function, modulo the specific namespace in which the
function is created.
Exactly. This question asked why staticmethod when we have classmethod. But the real question is why staticmethod at all?
And the answer is that there is very little use for staticmethod in Python -- all it does is put a regular function in the class' namespace, and since we have modules to be nice namespaces for functions, there is little need for it.
Sometimes it does make sense to keep some functionality all bundled together with a class, but I find it pretty rare.
Christopher Barker, PhD
Python Language Consulting
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython