Reputation: 7714
I have two classes that are dependent one another and are working fine without annotations. Unfortunately, when I try and annotate return values, it causes an expected circular dependency error.
Network.py
def processors(self) -> List[Processor]:
# implementation
Processor.py
def network(self) -> Network:
# implementation
How can I annotate without having to use the import
statement which causes a circular dependency?
Upvotes: 0
Views: 155
Reputation: 9726
You can use a forward reference:
def processors(self) -> List['Processor']:
# implementation
Yes, it looks a bit ugly, but it appears to be the intended solution.
Upvotes: 1