fix(python): correct type hint for to_tensor_fn parameter#5577
Merged
wjones127 merged 4 commits intolance-format:mainfrom Jan 12, 2026
Merged
Conversation
Fixes lance-format#3129 The type hint for in was declaring a single-argument callable, but the function is actually called with additional keyword arguments ( and ). Changes: - Update type hint to use to allow arbitrary args - Enhance docstring to document the expected function signature
wjones127
requested changes
Jan 1, 2026
Contributor
wjones127
left a comment
There was a problem hiding this comment.
Can we fix the type hint by making it correct and specific?
Comment on lines
+196
to
+198
| Callable[[pa.RecordBatch], Union[dict[str, torch.Tensor], torch.Tensor]] | ||
| Callable[ | ||
| ..., Union[dict[str, torch.Tensor], torch.Tensor] | ||
| ] |
Contributor
There was a problem hiding this comment.
It seems wrong to just make this more generic. How about this?
Callable[[pa.RecordBatch, ...], Union[dict[str, torch.Tensor], torch.Tensor]]Alternatively, can be fancier and do:
from typing import Protocol
class ToTensorFn(Protocol):
def __call__(self, batch: pa.RecordBatch, hf_converter, use_blob_api: bool) -> Union[dict[str, torch.Tensor], torch.Tensor]: ...
...
to_tensor_fn: ToTensorFn
Contributor
Author
There was a problem hiding this comment.
Thanks for pointing this out, i agree about the hint being too generic.
I modified it with the ' less fancy' approach + ran lint in the last commit
Contributor
Author
There was a problem hiding this comment.
I thought about your comment and this is probably the cleanest way i can come up with, what do you think?
wjones127
approved these changes
Jan 12, 2026
jackye1995
pushed a commit
to jackye1995/lance
that referenced
this pull request
Jan 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3129