What this PR does / why we need it:
Fixes mypy type checking error where TorchTensor was not recognized as a valid type alias:
feast/online_response.py:104: error: Variable "feast.online_response.TorchTensor" is not valid as a type [valid-type]
Root Cause
TypeAlias imported at module level while type alias defined conditionally inside TYPE_CHECKING block. Mypy cannot disambiguate whether TorchTensor is a variable or type alias.
Changes
Move TypeAlias import into both branches of TYPE_CHECKING conditional:
# Before
from typing import TYPE_CHECKING, Any, Dict, List, TypeAlias, Union
if TYPE_CHECKING:
import torch
TorchTensor: TypeAlias = torch.Tensor
else:
TorchTensor: TypeAlias = Any
# After
from typing import TYPE_CHECKING, Any, Dict, List, Union
if TYPE_CHECKING:
from typing import TypeAlias
import torch
TorchTensor: TypeAlias = torch.Tensor
else:
from typing import TypeAlias
TorchTensor: TypeAlias = Any
Type-checking only change. No runtime impact.
Misc
N/A
Original prompt
This section details on the original issue you should resolve
<issue_title>torch tensor type error with mypy</issue_title>
<issue_description>## Expected Behavior
Current Behavior
feast/online_response.py:104: error: Variable "feast.online_response.TorchTensor" is not valid as a type [valid-type]
Steps to reproduce
Specifications
- Version:
- Platform:
- Subsystem:
Possible Solution
</issue_description>
Comments on the Issue (you are @copilot in this section)
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.