error: 'staticmethod' object is not callable

Peter Otten __peter__ at web.de
Wed Feb 11 10:18:25 EST 2004


Michal Vitecek wrote:

> Peter Otten wrote:
>>You are wrapping method2() twice:
>>
>>class A(object):
>>    def method(parA):
>>        print "in A.method()"
>>    method = staticmethod(staticmethod(method))
>>
>>A.method("first")
>>
>>Why would you expect this to work?
> 
>  i don't expect this to work. i just don't get it why python allows this
>  double wrapping of a method. it cannot be used for anything reasonable,
>  can it?
> 

>>> import __builtin__
>>> def staticmethod(m):
...     assert callable(m), "staticmethod expects a callable as argument"                         
...     return __builtin__.staticmethod(m)
...
>>> class A(object):
...     def method():
...             pass
...     method = staticmethod(method)
...     method = staticmethod(method)
...
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 5, in A
  File "<stdin>", line 2, in staticmethod
AssertionError: staticmethod expects a callable as argument
>>>

Is this what you want then?
Personally, I don't care much, because 
(1) I use static methods very rarely. 
(2) The error message makes it clear enough that something's wrong with a
static method.

If you think it's important, you could either use a wrapper function like
above in your code or submit a patch.

Peter




More information about the Python-list mailing list