0

Please see the following example:

class MyClass(object):

    @staticmethod
    def __myStaticMethod(someArgs):
        pass

    MY_SPECIAL_METHOD_LIST = [
        __myStaticMethod
    ]

    @staticmethod
    def someOtherMethod():
        m = MyClass.MY_SPECIAL_METHOD_LIST[0]
        print(m)
        m()

If I now execute the statement MyClass.someOtherMethod() I get an exception:

<staticmethod object at 0x7fd672e69898>
Traceback (most recent call last):
  File "./test3.py", line 25, in <module>
    MyClass.someOtherMethod()
  File "./test3.py", line 21, in someOtherMethod
    m()
TypeError: 'staticmethod' object is not callable

Obviously m contains a reference to the static method. But I can not call this method. Why? What do I need to change in order to call this method?

martineau
  • 119,623
  • 25
  • 170
  • 301
Regis May
  • 3,070
  • 2
  • 30
  • 51

1 Answers1

0

In order to call a static method from inside your class you need to unwrap it. change m() to m.__func__('params') and you'll be good.

AlG
  • 14,697
  • 4
  • 41
  • 54