[Python-Dev] Making staticmethod objects callable? (original) (raw)

Nicolas Fleury nidoizo at yahoo.com
Wed Mar 1 20:28:40 CET 2006


Steven Bethard wrote:

My only (mild) concern is that if staticmethod is going to get a call, I think classmethod should probably get one too. Inside a class this doesn't make much sense:

I agree, make sense or not, if "@staticmethod def foo()" and a simple "def foo(self)" can all be called inside class definition, "@classmethod def foo(cls)" should too.

Anyway, my feeling was that running into this behavior (that staticmethod is not callable) is a good oportunity to explain how descriptors work. And once you start playing around with staticmethod and classmethod, you're going to need to learn that pretty soon anyway. Hiding it a little bit longer with a call method on staticmethod isn't going to help much in the long run.

The problem is that even after explaining descriptors (which IMHO can be a more advanced feature for newbies), you still need a workaround and you might end up with (or call get):

class A: def foo(): pass bar = foo() foo = staticmethod(foo)

Which I find sad considering all the energy debating @decorators;)

Regards, Nicolas



More information about the Python-Dev mailing list