-
Notifications
You must be signed in to change notification settings - Fork 673
Calling typing.get_type_hints
on a ModelHubMixin
breaks
#2727
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
Comments
one simple solution would be to fallback to import typing
from huggingface_hub import ModelHubMixin
class MyModel(ModelHubMixin): ...
def get_type_hints_safe(obj, ignore_errors=True):
try:
return typing.get_type_hints(obj)
except NameError:
return obj.__annotations__
my_model = MyModel()
get_type_hints_safe(my_model) output:
the initial issue comes from the fact that |
I'm using an external library (draccus) to serialize/deserialize from files or from cli commands our configs in LeRobot. Some of our configs are dataclasses which also happen to subclass Interestingly, they seem to have had the same issue and they redefine Adapting it here, it would look like this in if TYPE_CHECKING:
from _typeshed import DataclassInstance
else:
class DataclassInstance(Protocol):
__dataclass_fields__: ClassVar[Dict[str, Field]]
Dataclass = TypeVar("Dataclass", bound=DataclassInstance) And then in the rest of the file, replacing type annotations I've tried on my fork and it seems to do the trick, here's the PR if you want to check it out: #2729 |
Fixed by #2729 |
Awesome, thank you @hanouticelina! 🤗 |
Describe the bug
Calling
typing.get_type_hints
on a class inheriting fromModelHubMixin
gets you a NameError when that function tries to resolve its type because"DataclassInstance"
(which is whatModelHubMixin
uses in its annotations) doesn't seem to be available in the scope when that happens.I'll see if I can fix this and open a PR.
Reproduction
Logs
System info
The text was updated successfully, but these errors were encountered: