Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ unresolved-attribute = "ignore"

# Be tolerant with framework/typing edge-cases and runtime-validated code paths
unsupported-base = "ignore"
possibly-unbound-attribute = "ignore"
unsupported-operator = "ignore"
possibly-missing-attribute = "ignore"
possibly-missing-implicit-call = "ignore"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's safe to ignore https://docs.astral.sh/ty/reference/rules/#possibly-missing-attribute and https://docs.astral.sh/ty/reference/rules/#possibly-missing-implicit-call they are static analysis warnings that flag potential AttributeErrors if a class or object does not always define a given attribute or method.
they're safe to ignore because the code always defines those attributes or methods when it actually runs, the warning just comes from static analysis not realizing that

non-subscriptable = "ignore"
call-non-callable = "ignore"

Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/_webhooks_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from fastapi.responses import JSONResponse
else:
# Will fail at runtime if FastAPI is not available
FastAPI = Request = JSONResponse = None # type: ignore [misc, assignment]
FastAPI = Request = JSONResponse = None # type: ignore


_global_app: Optional["WebhooksServer"] = None
Expand Down
24 changes: 16 additions & 8 deletions src/huggingface_hub/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from dataclasses import dataclass
from datetime import datetime
from typing import List, Literal, Optional, Union
from typing import List, Literal, Optional, TypedDict, Union

from . import constants
from .utils import parse_datetime
Expand Down Expand Up @@ -143,6 +143,14 @@ class DiscussionWithDetails(Discussion):
diff: Optional[str]


class DiscussionEventArgs(TypedDict):
id: str
type: str
created_at: datetime
author: str
_event: dict


@dataclass
class DiscussionEvent:
"""
Expand Down Expand Up @@ -319,13 +327,13 @@ def deserialize_event(event: dict) -> DiscussionEvent:
event_type: str = event["type"]
created_at = parse_datetime(event["createdAt"])

common_args = dict(
id=event_id,
type=event_type,
created_at=created_at,
author=event.get("author", {}).get("name", "deleted"),
_event=event,
)
common_args: DiscussionEventArgs = {
"id": event_id,
"type": event_type,
"created_at": created_at,
"author": event.get("author", {}).get("name", "deleted"),
"_event": event,
}

if event_type == "comment":
return DiscussionComment(
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/serialization/_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def save_torch_state_dict(
safe_file_kwargs = {"metadata": per_file_metadata} if safe_serialization else {}
for filename, tensors in state_dict_split.filename_to_tensors.items():
shard = {tensor: state_dict[tensor] for tensor in tensors}
save_file_fn(shard, os.path.join(save_directory, filename), **safe_file_kwargs)
save_file_fn(shard, os.path.join(save_directory, filename), **safe_file_kwargs) # ty: ignore[invalid-argument-type]
logger.debug(f"Shard saved to {filename}")

# Save the index (if any)
Expand Down
Loading