Allow typing from missing dependency
ZanSara opened this issue · 0 comments
ZanSara commented
Problem
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:
import numpy as np
import torch
def my_complicated_function(device: torch.device) -> torch.tensor, np.ndarray:
...
Solution
I found that adding __args__ = []
in FakeModule
seems to fix the issue. I'm going to open a small PR for this case.