I'm trying to implement inheritance system where child class will add a value to dictionary that he received from ansister.
For instance:
class First:
specificator = {'first':1}
inherited_specificator = {}
def __init__(self, *args, **kwargs):
???
class Second(First):
specificator = {'second':2}
class Third(Second):
specificator = {'third':3}
So i wish I can implement init method that Third class instance will have inherited_specificator = {'first':1, 'second':2, 'third':3}
What I've tried:
Create init method that will be calling parent init method that will be calling... and so on to collect specificators from all top level classes.
class First:
specificator = {'first':1}
def __init__(self, *args, **kwargs):
super().__init__(args, kwargs)
if not getattr(self, 'inherited_specificator ', None): setattr(self, 'inherited_specificator', {})
self.inherited_specificator = {**self.inherited_specificator , **self.specificator}
However it didn't work for me for some reason, Third().inherited_specificator was equal to {'third':3}. Maybe I don't completely understand the super() method workstyle, but I wasn't able to find detailed info about my case.
Also I tried to create set_specificator function that will be called from init and where it should add current class specificator to inherited one, but the same problem appeared and all I got is {'third':3}.
If there's solution for my case? Thanks in advance.
Update:
I'm looking for solution without overwriting init method if possible