staticmethod makes my brain hurt
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Nov 16 23:43:24 EST 2011
On Wed, 16 Nov 2011 21:30:57 -0500, Roy Smith wrote:
> When I run this (python 2.6.1):
>
> class C:
> @staticmethod
> def foo():
> pass
> print "inside", foo, callable(foo)
>
> print "outside", C.foo, callable(C.foo)
>
> I get:
>
> inside <staticmethod object at 0x421df0> False
> outside <function foo at 0x41e6f0> True
>
> I don't understand. Why is foo not callable inside of the class
> definition?
This has come up before.
http://bytes.com/topic/python/answers/34396-static-method-object-not-callable
http://bytes.com/topic/python/answers/462734-make-staticmethod-objects-callable
However, the fix is not as simple as merely making staticmethod objects
callable. This was discussed at the 2011 language summit:
http://www.boredomandlaziness.org/2011/03/python-language-summit-rough-notes.html
See also this thread:
http://mail.python.org/pipermail/python-dev/2011-March/109090.html
--
Steven
More information about the Python-list
mailing list