You can do something similar to the referenced answer except remove the items that are specific to your subclass.
class Thing:
def __init__(self, arg1, arg2, arg3, arg4, kw1=None, kw2=None):
print('Thing args:',arg1,arg2,arg3,arg4)
print('Thing kw:',kw1,kw2)
class SubThing(Thing):
def __init__(self, *args, **kw):
"""SubThing(arg1, arg2, arg3, arg4, arg5, arg6, kw1=None, kw2=None,
kw3=None, kw4=None)
"""
if len(args) != 6:
raise TypeError(
"SubThing() takes 6 positional arguments but {} were given"
.format(len(args)))
arg5, arg6 = args[4:]
kw3 = kw.pop('kw3', None)
kw4 = kw.pop('kw4', None)
super().__init__(*args[:4], **kw)
SubThing(1,2,3,4,5,6,kw1='kw1',kw4='kw4')
print('---- but populating kwargs from positional args stops working ----')
Thing(1,2,3,4, 'kw1', 'kw2')
SubThing(1,2,3,4,5,6,'kw1','kw2')
This results in
Thing args: 1 2 3 4
Thing kw: kw1 None
---- but populating kwargs from positional args stops working ----
Thing args: 1 2 3 4
Thing kw: kw1 kw2
Traceback (most recent call last):
File "n.py", line 24, in <module>
SubThing(1,2,3,4,5,6,'kw1','kw2')
File "n.py", line 14, in __init__
.format(len(args)))
TypeError: SubThing() takes 6 positional arguments but 8 were given
Notice in the second example, you lost some functionality because extra positional arguments didn't automatically fill in keyword arguments. You can fix that with more coding or just accept the restrictions. Lots of classes that use *args, **kw
forget to do that so you are in good company.