Superclass static method name from subclass
Cameron Simpson
cs at cskk.id.au
Fri Nov 11 17:36:16 EST 2022
On 12Nov2022 09:17, Cameron Simpson <cs at cskk.id.au> wrote:
>On 11Nov2022 10:21, Ian Pilcher <arequipeno at gmail.com> wrote:
>> class SubClass(SuperClass):
>> bar = SuperClass.foo
>> ^^^^^^^^^^
>>
>>Is there a way to do this without specifically naming 'SuperClass'?
>
>I think not.
Then I saw your "Dealing with non-callable classmethod objects" post
which mentions `__init_subclass__`. Which feels like I've read about
that before, but had entirely slipped my mind.
Maybe:
class SubClass(SuperClass):
@classmethod
def __init__subclass__(cls):
cls.bar = super().foo
would do the trick. Looks clean, but I haven't tried it yet.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Python-list
mailing list