I have a package which contain several files. Each file contains a class and the classes are interdependant. How can I avoid circular dependencies without putting all the code in one file. Is there a better way to refactor the code or is there a way to resolve the circular imports
This is the directory structure
.
|-- Complainant.py
|-- Complaint.py
`-- __init__.py
Complaint.py:
from .Complainant import Complainant
class Complaint(BaseDocument):
ALL_STATUS = ["waiting","resolved", "rejected"]
text = TextField()
timestamp = DateTimeField()
status = TextField()
complainant_id = TextField()
department_ids = ListField(TextField())
def get_complainant(self):
db = DBManager.db()
complainant = Complainant.load(db, self.complainant_id)
return complainant
Complainant.py
from .Complaint import Complaint
class Complainant(BaseDocument):
account_type = TextField()
account_handle = TextField()
complaint_ids = ListField(TextField())
def get_complaints(self):
db = DBManager.db()
complaints = [Complaint.load(db, i) for i in self.complaint_ids]
return complaints
init.py
from .Complaint import Complaint
from .Complainant import Complainant
__all__ = [
Complaint,
Complainant
]