Skip to content

Comments

fix: Resolve mypy [valid-type] error for TorchTensor TypeAlias#5984

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-torch-tensor-type-error
Draft

fix: Resolve mypy [valid-type] error for TorchTensor TypeAlias#5984
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-torch-tensor-type-error

Conversation

Copy link
Contributor

Copilot AI commented Feb 18, 2026

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.

…e TYPE_CHECKING blocks

Co-authored-by: franciscojavierarceo <4163062+franciscojavierarceo@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix torch tensor type error with mypy fix: resolve mypy [valid-type] error for TorchTensor TypeAlias Feb 18, 2026
Copy link
Collaborator

@jyejare jyejare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, needs to rerun checks I think.

@franciscojavierarceo franciscojavierarceo changed the title fix: resolve mypy [valid-type] error for TorchTensor TypeAlias fix: Resolve mypy [valid-type] error for TorchTensor TypeAlias Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

torch tensor type error with mypy

3 participants