ty icon indicating copy to clipboard operation
ty copied to clipboard

ty reports unknown-argument for Hugging Face tool choice dataclasses

Open dsfaccini opened this issue 3 weeks ago • 3 comments

Summary

Ty reports unknown-argument for valid fields on Hugging Face chat tool choice dataclasses.

NOTE: I can't reproduce this in the playground when trying to write the example without the hugging face dependency https://play.ty.dev/0bb1b12d-1ea7-449b-b6cf-18c20f21027f

Nonetheless I do get the error when I use the hugging face package, so this may be something to bring up with the hugging face team

Image

Repro (self-contained)

ty_repro_hf.py:

# /// script
# dependencies = [
#     "huggingface_hub>=0.26",
# ]
# ///

from typing import Literal
from huggingface_hub import ChatCompletionInputFunctionName, ChatCompletionInputToolChoiceClass


def build_tool_choice(name: str) -> ChatCompletionInputToolChoiceClass:
    return ChatCompletionInputToolChoiceClass(
        function=ChatCompletionInputFunctionName(name=name)
    )


def main() -> Literal["ok"]:
    build_tool_choice("foo")
    return "ok"


if __name__ == "__main__":
    print(main())

Run:

uvx ty check ty_repro_hf.py

Actual result

error[unknown-argument]: Argument `function` does not match any known parameter
  --> ty_repro_hf.py:13:9
...
error[unknown-argument]: Argument `name` does not match any known parameter
  --> ty_repro_hf.py:13:50
...

Expected result

No diagnostics: the generated HF dataclasses expose function and name (see huggingface_hub/inference/_generated/types/chat_completion.py in the installed package).

Notes

Looks like ty isn't recognizing the dataclass fields on these generated classes.

dsfaccini avatar Dec 21 '25 04:12 dsfaccini

I think Pyright has the same behavior here, at least:

/Users/crmarsh/workspace/ruff/ty_repro_hf.py
  /Users/crmarsh/workspace/ruff/ty_repro_hf.py:13:9 - error: No parameter named "function" (reportCallIssue)
  /Users/crmarsh/workspace/ruff/ty_repro_hf.py:13:50 - error: No parameter named "name" (reportCallIssue)
2 errors, 0 warnings, 0 informations

AFAICT they have a custom dataclass transform that isn't marked with @dataclass_transform: https://github.com/huggingface/huggingface_hub/blob/b3a8754d6fd16ee888cc155b359464b4451afac7/src/huggingface_hub/inference/_generated/types/base.py#L32

charliermarsh avatar Dec 21 '25 13:12 charliermarsh

Fixed upstream in https://github.com/huggingface/huggingface_hub/pull/3639.

charliermarsh avatar Dec 21 '25 14:12 charliermarsh

awesome, appreciated!

dsfaccini avatar Dec 21 '25 14:12 dsfaccini

Hey there! Maintainer of the huggingface_hub library here 👋. I've just released huggingface_hub v1.2.4 with @charliermarsh 's fix :hugs:

https://github.com/huggingface/huggingface_hub/releases/tag/v1.2.4

And confirmed locally that the repro example now works:

Image

Wauplin avatar Jan 06 '26 11:01 Wauplin

Thanks so much @Wauplin!!

AlexWaygood avatar Jan 06 '26 11:01 AlexWaygood