Superclass static method name from subclass

Dieter Maurer dieter at handshake.de
Fri Nov 11 12:29:35 EST 2022


Ian Pilcher wrote at 2022-11-11 10:21 -0600:
>Is it possible to access the name of a superclass static method, when
>defining a subclass attribute, without specifically naming the super-
>class?
>
>Contrived example:
>
>   class SuperClass(object):
>       @staticmethod
>       def foo():
>           pass
>
>   class SubClass(SuperClass):
>       bar = SuperClass.foo
>             ^^^^^^^^^^
>
>Is there a way to do this without specifically naming 'SuperClass'?

Unless you overrode it, you can use `self.foo` or `SubClass.foo`;
if you overrode it (and you are using either Python 3 or
Python 2 and a so called "new style class"), you can use `super`.
When you use `super` outside a method definition, you must
call it with parameters.


More information about the Python-list mailing list