I'm trying to work with circular dependency on python (yes, it is needed because I need to separate my models on different files and modules).
I tried several ways to approach this (most of them already suggested by related questions) but none of them resolved the problem. Note: when a remove the circular dependency, the code works.
defer import
/module_a/class_a.py
from module_b.class_b import B class A: b = B()
/module_b/class_b.py
class B: from module_a.class_a import A a = A()
defer both imports
/module_a/class_a.py
class A: from module_b.class_b import B b = B()
/module_b/class_b.py
class B: from module_a.class_a import A a = A()
not using from .. import notation
/module_a/class_a.py
import module_b.class_b as mb class A: b = mb.B()
/module_b/class_b.py
import module_a.class_a as ma class B: a = ma.A()
not using from .. import notation with defer import
/module_a/class_a.py
class A: import module_b.class_b as mb b = mb.B()
/module_b/class_b.py
class B: import module_a.class_a as ma a = ma.A()
The result is that none of the solutions worked. I don't know if it has to do with the fact that the call is on the class definition, but it needs to be this way cause I'm using an ORM.