Skip to content

fix: Fix mypy TorchTensor type alias error - #6712

Merged
jyejare merged 2 commits into
feast-dev:masterfrom
nithin42:fix/online-response-mypy
Aug 10, 2026
Merged

fix: Fix mypy TorchTensor type alias error#6712
jyejare merged 2 commits into
feast-dev:masterfrom
nithin42:fix/online-response-mypy

Conversation

@nithin42

@nithin42 nithin42 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it

In online_response.py, TorchTensor is defined using TypeAlias inside both conditional branches of if TYPE_CHECKING:. Mypy complains: Variable "feast.online_response.TorchTensor" is not valid as a type because it parses it as a variable inside the runtime fallback branch.
This PR fixes the typing syntax in online_response.py by defining TorchTensor cleanly without TypeAlias in the fallback branch so mypy parses the type correctly.

Which issue(s) this PR fixes

Fixes #5563

Checks

  • I've made sure the tests are passing.
  • My commits are signed off (git commit -s)
  • My PR title follows conventional commits format

@jyejare jyejare left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, just nitpick.

Comment thread sdk/python/feast/online_response.py Outdated
@@ -26,10 +26,9 @@

if TYPE_CHECKING:
import torch

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This must not be needed anymore.

@nithin42

Copy link
Copy Markdown
Contributor Author

Good catch — removed the redundant import torch in commit 2704e66. Since TorchTensor is the only torch symbol used in type annotations, the standalone module import was indeed no longer needed after the fix.

@nithin42
nithin42 requested a review from jyejare August 10, 2026 11:30
Fix the TypeAlias annotation of TorchTensor in the fallback branch of online_response.py to stop mypy from treating it as a variable and raising 'not valid as a type'.

Fixes feast-dev#5563

Signed-off-by: Nithin <kumbam.nithingoud@gmail.com>
@nithin42
nithin42 force-pushed the fix/online-response-mypy branch from 6765bd1 to 0cbce28 Compare August 10, 2026 11:33
The bare `import torch` statement inside the `if TYPE_CHECKING:` branch
was superseded by `from torch import Tensor as TorchTensor` on the
following line. Since `TorchTensor` is the only torch symbol referenced
in type annotations, the standalone module import is unnecessary and
can be dropped without affecting runtime or static-analysis behaviour.

Addresses nitpick raised in code review.

Signed-off-by: Nithin <kumbam.nithingoud@gmail.com>
@nithin42
nithin42 force-pushed the fix/online-response-mypy branch from 0cbce28 to a0c040f Compare August 10, 2026 11:34
@nithin42

nithin42 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

@jyejare @ntkathole @franciscojavierarceo — the nitpick is fixed and DCO is green. Could you please approve the workflow runs for this PR so CI can finish and it can be merged? Thank you!

@codecov-commenter

codecov-commenter commented Aug 10, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.76%. Comparing base (037c4cd) to head (a0c040f).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #6712   +/-   ##
=======================================
  Coverage   46.76%   46.76%           
=======================================
  Files         415      415           
  Lines       50392    50392           
  Branches     7214     7214           
=======================================
  Hits        23567    23567           
  Misses      25171    25171           
  Partials     1654     1654           
Flag Coverage Δ
go-feature-server 30.58% <ø> (ø)
python-unit 48.09% <100.00%> (ø)
Files with missing lines Coverage Δ
sdk/python/feast/online_response.py 75.36% <100.00%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 037c4cd...a0c040f. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jyejare
jyejare merged commit 34de6fa into feast-dev:master Aug 10, 2026
23 checks passed
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