I’m trying to use __init_subclass__
in ‘mixins’ but have hit a problem if two __init_subclass__
s have the same argument name. EG msg
below:
class A:
def __init_subclass__(cls, msg, **kwargs):
print(f'A: {msg}')
super().__init_subclass__(**kwargs)
class B:
def __init_subclass__(cls, msg, **kwargs):
print(f'B: {msg}')
super().__init_subclass__(**kwargs)
class AB(A, B, msg='Hello from AB'): ...
Which gives the error:
A: Hello from AB
Traceback (most recent call last):
File <snip>, in <module>
class AB(A, B, msg='Hello from AB'): ...
File <snip> in __init_subclass__
super().__init_subclass__(**kwargs)
TypeError: B.__init_subclass__() missing 1 required positional argument: 'msg'
Is there a way round this other than using unique argument names?