by capableweb · 3y ago · 0 comments
if TYPE_CHECKING: import WhateverClass
https://docs.python.org/3/library/typing.html#typing.TYPE_CH...
(And some types are defined in the typeshed so only exist to be imported during type checking; eg the type checker lib itself is a dependency in this case)
from typing import List
class Alpha:
@staticmethod
def doit(b: "Beta") -> List["Beta"]:
return [b]
class Beta:
@staticmethod
def doit(a: "Alpha") -> List["Alpha"]:
return [a] import gamma
def doit(bar: "gamma.Gamma"): ...
In Java my answer to circular deps is the introduction of an interface that the concrete types can implement but then breaks the cycle