This may have been asked before, but most questions seem to be about the more basic question of "how to import local class"
I'm working on a module with two classes which reference each other. Ex. instances of Foo
have a property of type Bar
. But at the same time, in the class Bar
I have a method which references the class Foo
.
Both of these classes are in separate files and are exported by the module's __init__.py
.
I assumed python would simply allow me to use Foo
in bar.py
and Bar
in foo.py
, but instead I get a name not defined error when trying to call methods where the cross references occur. How can I import these classes? If I try to add from .bar import Bar
in foo.py
, I get a circular dependency error when trying to import the module. I'm not sure how to resolve this issue.