6 ms·
In python it's very hard to avoid cyclic dependencies. Something as simple as a parent-child link between two classes is a cyclic dependency, and if the classes
by maxcoder4 3y ago
In python it's very hard to avoid cyclic dependencies. Something as simple as a parent-child link between two classes is a cyclic dependency, and if the classes are in different files you have a car like in the blog post. This comes up especially hard when typing your codebase, because you have to name every type, and in python implementation is the interface, i.e. you can't just include a type definition file.
- remram 3y ago> parent-child link between two classes is a cyclic dependency What do you mean? Where is the cycle?
- coryrc 3y agoclass Parent: children : List[Child] class Child: __init__(self, parent: Parent):
- remram 3y agoAh yes, it might be what they mean. I assumed inheritance. Thanks.
- diarrhea 3y agoI also wonder. If a child class knows its concrete parent (apart from where inheritance is declared), and not just references it via super(), things have already gone badly wrong.
- MereInterest 3y agoThe parent holds a reference to the child. The child holds a reference to the parent.
- remram 3y agoWhy does the parent hold a reference to the child? Are you talking about a specific pattern or implementation detail in the interpreter? Because I would not call this "dependency"...
- gpderetta 3y agoParametrize the parent with the child and the child with the parent. Tie the knot after both are defined.