Skip to content

Commit

Permalink
mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoestq committed Oct 31, 2024
1 parent 90b1c5d commit 3014429
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/huggingface_hub/_webhooks_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
"""Contains data structures to parse the webhooks payload."""

from typing import Any, List, Literal, Optional
from typing import Any, List, Literal, Optional, Union

from .utils import is_pydantic_available

Expand Down Expand Up @@ -47,14 +47,14 @@ def schema(cls, *args, **kwargs) -> dict[str, Any]:
)

@classmethod
def model_validate_json(cls, json_data: str | bytes | bytearray, *args, **kwargs) -> "BaseModel":
def model_validate_json(cls, json_data: Union[str, bytes, bytearray], *args, **kwargs) -> "BaseModel":
raise ImportError(
"You must have `pydantic` installed to use `WebhookPayload`. This is an optional dependency that"
" should be installed separately. Please run `pip install --upgrade pydantic` and retry."
)

@classmethod
def parse_raw(cls, json_data: str | bytes | bytearray, *args, **kwargs) -> "BaseModel":
def parse_raw(cls, json_data: Union[str, bytes, bytearray], *args, **kwargs) -> "BaseModel":
raise ImportError(
"You must have `pydantic` installed to use `WebhookPayload`. This is an optional dependency that"
" should be installed separately. Please run `pip install --upgrade pydantic` and retry."
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/inference/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ def chat_completion(
ActivitySummary(location='park', activity='bike ride', animals_seen=3, animals=['puppy', 'cat', 'raccoon'])
```
"""
if issubclass(response_format, BaseModel):
if isinstance(response_format, type) and issubclass(response_format, BaseModel):
response_model = response_format
response_format = ChatCompletionInputGrammarType(
type="json",
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/inference/_generated/_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ async def chat_completion(
ActivitySummary(location='park', activity='bike ride', animals_seen=3, animals=['puppy', 'cat', 'raccoon'])
```
"""
if issubclass(response_format, BaseModel):
if isinstance(response_format, type) and issubclass(response_format, BaseModel):
response_model = response_format
response_format = ChatCompletionInputGrammarType(
type="json",
Expand Down

0 comments on commit 3014429

Please sign in to comment.