Let's say I have two classes in two files:
from Son import Son
class Mother:
def __init__(self):
self.sons = []
def add_son(self, son: Son):
self.sons.append(son)
and
from Mother import Mother
class Son:
def __init__(self, mother: Mother):
self.mother = mother
mother.add_son(self)
Plus main file
from Mother import Mother
from Son import Son
if __name__ == '__main__':
mother = Mother()
son1 = Son(mother)
son2 = Son(mother)
Obviously, I have a circular addiction. How to deal with this behavior without losing the type of hint?
source
share