Imagine you have a basic tensor class with softmax. Softmax is a random example here.
from .nn import Softmax
class Tensor(data):
def __init__():
self.data = data
def softmax():
return Softmax()
and you have this Softmax implementation in nn.softmax.py
from .tensor import Tensor
def Softmax(data):
#Â do fancy math
result = ...
return Tensor(result)
Now we can do:
# import Tensor, Softmax
X = tensor(...)
X.softmax()
Softmax(X)
the current design is flawed though because we have a circular dependency: Tensor::softmax() uses Softmax() which uses Tensor which uses ....
How can I solve this?
Edit: Without using TYPE_CHECKING for type hints and moving the import Tensor inside of Softmax(). I want to avoid import inside functions.