Closed ZanSara closed 1 year ago
In Haystack we often need to type method signatures with missing dependencies. Something like:
import numpy as np import torch def my_complicated_function(device: Optional[torch.device]) -> Union[torch.tensor, np.ndarray]: ...
I found that torch.device, torch.tensor and np.ndarray trigger generalimport once wrapped in a container like Optional or Union, while they don't when they're unwrapped, like:
torch.device
torch.tensor
np.ndarray
generalimport
Optional
Union
import numpy as np import torch def my_complicated_function(device: torch.device) -> torch.tensor, np.ndarray: ...
I found that adding __args__ = [] in FakeModule seems to fix the issue. I'm going to open a small PR for this case.
__args__ = []
FakeModule
Problem
In Haystack we often need to type method signatures with missing dependencies. Something like:
I found that
torch.device
,torch.tensor
andnp.ndarray
triggergeneralimport
once wrapped in a container likeOptional
orUnion
, while they don't when they're unwrapped, like:Solution
I found that adding
__args__ = []
inFakeModule
seems to fix the issue. I'm going to open a small PR for this case.