From 494d0f63da4180e6ce7037958cc7d3d588a67a49 Mon Sep 17 00:00:00 2001 From: ahmdayyy Date: Thu, 18 Jan 2024 15:39:56 +0100 Subject: [PATCH 1/3] updated hfapi objects to use dataclass --- src/huggingface_hub/hf_api.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/huggingface_hub/hf_api.py b/src/huggingface_hub/hf_api.py index 3adbad679a..5fa08340b2 100644 --- a/src/huggingface_hub/hf_api.py +++ b/src/huggingface_hub/hf_api.py @@ -238,10 +238,14 @@ def repo_type_and_id_from_hf_id(hf_id: str, hub_url: Optional[str] = None) -> Tu return repo_type, namespace, repo_id -class LastCommitInfo(TypedDict, total=False): +@dataclass +class LastCommitInfo(dict): oid: str title: str date: datetime + + def __post_init__(self): # hack to make BlobLfsInfo backward compatible + self.update(asdict(self)) @dataclass @@ -253,12 +257,14 @@ class BlobLfsInfo(dict): def __post_init__(self): # hack to make BlobLfsInfo backward compatible self.update(asdict(self)) - -class BlobSecurityInfo(TypedDict, total=False): +@dataclass +class BlobSecurityInfo(dict): safe: bool av_scan: Optional[Dict] pickle_import_scan: Optional[Dict] + def __post_init__(self): # hack to make BlobLfsInfo backward compatible + self.update(asdict(self)) class TransformersInfo(TypedDict, total=False): auto_model: str @@ -268,10 +274,14 @@ class TransformersInfo(TypedDict, total=False): processor: Optional[str] -class SafeTensorsInfo(TypedDict, total=False): +@dataclass +class SafeTensorsInfo(dict): parameters: List[Dict[str, int]] total: int + def __post_init__(self): # hack to make BlobLfsInfo backward compatible + self.update(asdict(self)) + @dataclass class CommitInfo(str): From 79d8192b7472546f8a1c49ee191f177896122139 Mon Sep 17 00:00:00 2001 From: ahmdayyy Date: Thu, 18 Jan 2024 15:42:03 +0100 Subject: [PATCH 2/3] updated hfapi obj to use dataclass --- src/huggingface_hub/hf_api.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/huggingface_hub/hf_api.py b/src/huggingface_hub/hf_api.py index 5fa08340b2..e66de05454 100644 --- a/src/huggingface_hub/hf_api.py +++ b/src/huggingface_hub/hf_api.py @@ -243,7 +243,7 @@ class LastCommitInfo(dict): oid: str title: str date: datetime - + def __post_init__(self): # hack to make BlobLfsInfo backward compatible self.update(asdict(self)) @@ -257,6 +257,7 @@ class BlobLfsInfo(dict): def __post_init__(self): # hack to make BlobLfsInfo backward compatible self.update(asdict(self)) + @dataclass class BlobSecurityInfo(dict): safe: bool @@ -266,6 +267,7 @@ class BlobSecurityInfo(dict): def __post_init__(self): # hack to make BlobLfsInfo backward compatible self.update(asdict(self)) + class TransformersInfo(TypedDict, total=False): auto_model: str custom_class: Optional[str] From 0b106933693e4bf34f4f12a05ca18635b1acfb9f Mon Sep 17 00:00:00 2001 From: ahmdayyy Date: Thu, 18 Jan 2024 18:13:12 +0100 Subject: [PATCH 3/3] updated comments for backward compatibility --- src/huggingface_hub/hf_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/huggingface_hub/hf_api.py b/src/huggingface_hub/hf_api.py index e66de05454..966c0e70b9 100644 --- a/src/huggingface_hub/hf_api.py +++ b/src/huggingface_hub/hf_api.py @@ -244,7 +244,7 @@ class LastCommitInfo(dict): title: str date: datetime - def __post_init__(self): # hack to make BlobLfsInfo backward compatible + def __post_init__(self): # hack to make LastCommitInfo backward compatible self.update(asdict(self)) @@ -264,7 +264,7 @@ class BlobSecurityInfo(dict): av_scan: Optional[Dict] pickle_import_scan: Optional[Dict] - def __post_init__(self): # hack to make BlobLfsInfo backward compatible + def __post_init__(self): # hack to make BlogSecurityInfo backward compatible self.update(asdict(self)) @@ -281,7 +281,7 @@ class SafeTensorsInfo(dict): parameters: List[Dict[str, int]] total: int - def __post_init__(self): # hack to make BlobLfsInfo backward compatible + def __post_init__(self): # hack to make SafeTensorsInfo backward compatible self.update(asdict(self))