error: 'staticmethod' object is not callable

Peter Otten __peter__ at web.de
Wed Feb 11 06:33:00 EST 2004


Michal Vitecek wrote:

>  hello everyone,
> 
>  today i've come upon a strange exception, consider the following file
>  test.py:
> 
> --- beginning of test.py ---
> 
> class A(object):
>     def method1(parA):
>         print "in A.method1()"
>     method1 = staticmethod(method1)
> 
>     def method2(parA, parB):
>         print "in A.method2()"
>     method1 = staticmethod(method1)
>     # see (*)
>     
> A.method1("some value")
> 
> --- end of test.py ---
> 
>  when test.py is run, the following error is printed:
> 
> $ python test.py
> Traceback (most recent call last):
>   File "test.py", line 10, in ?
>     A.method1("some value")
> TypeError: 'staticmethod' object is not callable
> $
> 
>  isn't this a bug somewhere in python? this was tested on 2.2.3.
> 
>  (*) this happened accidentaly by copy & paste error

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?

Peter




More information about the Python-list mailing list