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

Updating HfApi objects to use dataclass #1988

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,15 @@ 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 LastCommitInfo backward compatible
self.update(asdict(self))


@dataclass
class BlobLfsInfo(dict):
Expand All @@ -254,11 +258,15 @@ 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 BlogSecurityInfo backward compatible
self.update(asdict(self))


class TransformersInfo(TypedDict, total=False):
auto_model: str
Expand All @@ -268,10 +276,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 SafeTensorsInfo backward compatible
self.update(asdict(self))


@dataclass
class CommitInfo(str):
Expand Down
Loading