Python - override static method

How to override a static method and keep it static?

In [6]: class Foo(object): ...: @staticmethod ...: def foo(a, b): ...: print a + b ...: ...: In [7]: Foo.foo Out[7]: <function foo at 0x86a1a74> In [8]: class Bar(Foo): ...: def foo(a, b): ...: print a - b ...: ...: In [9]: Bar.foo Out[9]: <unbound method Bar.foo> 

I tried to decorate Bar foo with a static method and it works. But I have to subclass it every time.

+4
source share
1 answer

The way you should do it. In other programming languages, you should also use the static .

+4
source

Source: https://habr.com/ru/post/1391095/


All Articles