Why doesn't super() work with static methods other than __new__?

Viewed 3015

I understand that __new__ is a static method and super() can be called from it create a new object, like so:

>>> class A:
...     def __new__(cls):
...         print('__new__ called')
...         return super().__new__(cls)
...
>>> a = A()
__new__ called

Why doesn't the super call work with other static methods? Why does the following fail?

>>> class B:
...     @staticmethod
...     def funcB():
...         print('funcB called')
...
>>> class C(B):
...     @staticmethod
...     def funcC():
...         print('funcC called')
...         super().funcB()
...
>>> c = C()
>>> c.funcC()
funcC called
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 5, in funcC
RuntimeError: super(): no arguments
4 Answers

the solution is to use "classmethod" instead of "staticmethod" for example

class A:
    @staticmethod
    def a():
        return "in a"
    @classmethod
    def foo(cls):
        print(cls.a())

class B(A):
    @staticmethod
    def a():
        return "in b"

B.foo()
## in b
Related