Is there an elegant way to import type hints without circular imports?
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)
if False:
import blah
unironically as good design and more than a necessary evil until a long-term solution emerges then we’ve jumped the shark. 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