Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling typing.get_type_hints on a ModelHubMixin causes an error. #2737

Closed
Danishrose35 opened this issue Jan 5, 2025 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@Danishrose35
Copy link

Describe the bug

Calling typing.get_type_hints on a class that inherits from ModelHubMixin results in a NameError when trying to resolve its type. This happens because "DataclassInstance" (used in ModelHubMixin annotations) isn't available in the scope at the time.

I'll look into fixing this and submit a PR.

Reproduction

import typing
from huggingface_hub import ModelHubMixin

class MyModel(ModelHubMixin): ...

my_model = MyModel()
typing.get_type_hints(type(my_model))

Logs

Traceback (most recent call last):
  File "/Users/simon/projects/draccus/demo2.py", line 7, in <module>
    typing.get_type_hints(my_model)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/hub_310/lib/python3.10/typing.py", line 1871, in get_type_hints
    value = _eval_type(value, globalns, localns)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/hub_310/lib/python3.10/typing.py", line 329, in _eval_type
    ev_args = tuple(_eval_type(a, globalns, localns, recursive_guard) for a in t.__args__)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/hub_310/lib/python3.10/typing.py", line 329, in <genexpr>
    ev_args = tuple(_eval_type(a, globalns, localns, recursive_guard) for a in t.__args__)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/hub_310/lib/python3.10/typing.py", line 327, in _eval_type
    return t._evaluate(globalns, localns, recursive_guard)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/hub_310/lib/python3.10/typing.py", line 694, in _evaluate
    eval(self.__forward_code__, globalns, localns),
  File "<string>", line 1, in <module>
NameError: name 'DataclassInstance' is not defined

System info

huggingface_hub Version: 0.27.0
Platform: macOS-15.2-arm64-arm-64bit
Python Version: 3.10.16
Running in iPython?: No
Running in Notebook?: No
Running in Google Colab?: No
Running in Google Colab Enterprise?: No
Token Path: /Users/simon/.cache/huggingface/token
Has Saved Token?: Yes
User: aliberts
Configured Git Credential Helpers: cache, osxkeychain
FastAI: Not Available
TensorFlow: Not Available
Torch: Not Available
Jinja2: Not Available
Graphviz: Not Available
Keras: Not Available
Pydot: Not Available
Pillow: Not Available
hf_transfer: Not Available
Gradio: Not Available
Tensorboard: Not Available
NumPy: Not Available
Pydantic: Not Available
aiohttp: Not Available
Endpoint: https://huggingface.co
HF Hub Cache: /Users/simon/.cache/huggingface/hub
HF Assets Cache: /Users/simon/.cache/huggingface/assets
HF Token Path: /Users/simon/.cache/huggingface/token
HF Stored Tokens Path: /Users/simon/.cache/huggingface/stored_tokens
HF Hub Offline: False
HF Hub Disable Telemetry: False
HF Hub Disable Progress Bars: None
HF Hub Disable Symlinks Warning: False
HF Hub Disable Experimental Warning: False
HF Hub Disable Implicit Token: False
HF Hub Enable HF Transfer: False
HF Hub ETag Timeout: 10
HF Hub Download Timeout: 10
@Danishrose35 Danishrose35 added the bug Something isn't working label Jan 5, 2025
@hanouticelina
Copy link
Contributor

Hi @Danishrose35, sorry you encountered this issue! a PR #2729 is open to fix this.
I'll close this issue as duplicated of #2727.

@hanouticelina hanouticelina closed this as not planned Won't fix, can't repro, duplicate, stale Jan 6, 2025
@hanouticelina
Copy link
Contributor

@Danishrose35 we've just released a patch 0.27.1 for huggingface_hub that contains a fix for this issue!

pip install huggingface_hub==0.27.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants