Skip to content

Commit d373153

Browse files
Wauplinhanouticelina
authored andcommitted
Fix forward ref validation if total false (#3423)
1 parent 8b7c621 commit d373153

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/huggingface_hub/dataclasses.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,11 @@ def type_validator(name: str, value: Any, expected_type: Any) -> None:
431431
elif origin is Required:
432432
if value is _TYPED_DICT_DEFAULT_VALUE:
433433
raise TypeError(f"Field '{name}' is required but missing.")
434-
_validate_simple_type(name, value, args[0])
434+
type_validator(name, value, args[0])
435435
elif origin is NotRequired:
436436
if value is _TYPED_DICT_DEFAULT_VALUE:
437437
return
438-
_validate_simple_type(name, value, args[0])
438+
type_validator(name, value, args[0])
439439
else:
440440
raise TypeError(f"Unsupported type for field '{name}': {expected_type}")
441441

tests/test_utils_strict_dataclass.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,13 @@ class ConfigDict(TypedDict):
671671
optional_value: Optional[int]
672672

673673

674+
class ConfigDictIncomplete(TypedDict, total=False):
675+
str_value: str
676+
positive_int_value: Annotated[int, positive_int]
677+
forward_ref_value: "ForwardDtype"
678+
optional_value: Optional[int]
679+
680+
674681
@pytest.mark.parametrize(
675682
"data",
676683
[
@@ -680,6 +687,7 @@ class ConfigDict(TypedDict):
680687
)
681688
def test_typed_dict_valid_data(data: dict):
682689
validate_typed_dict(ConfigDict, data)
690+
validate_typed_dict(ConfigDictIncomplete, data)
683691

684692

685693
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)