Skip to content

Commit de54b65

Browse files
committed
chore: improve mypy
1 parent 0f5cb59 commit de54b65

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pydantic/validators.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
Number = Union[int, float, Decimal]
5151
StrBytes = Union[str, bytes]
5252

53+
class TypedDict(Dict[str, Any]):
54+
__annotations__: Dict[str, Type[Any]]
55+
__total__: bool
56+
5357

5458
def str_validator(v: Any) -> Union[str]:
5559
if isinstance(v, str):
@@ -549,16 +553,16 @@ def named_tuple_validator(values: Tuple[Any, ...]) -> NamedTupleT:
549553
return named_tuple_validator
550554

551555

552-
def make_typed_dict_validator(type_: Type[Dict[str, Any]]) -> Callable[[Any], Dict[str, Any]]:
556+
def make_typed_dict_validator(type_: Type['TypedDict']) -> Callable[[Any], Dict[str, Any]]:
553557
from .main import create_model
554558

555559
field_definitions: Dict[str, Any] = {
556-
field_name: (field_type, ... if field_name in type_.__required_keys__ else None)
560+
field_name: (field_type, ... if type_.__total__ else None)
557561
for field_name, field_type in type_.__annotations__.items()
558562
}
559563
TypedDictModel: Type['BaseModel'] = create_model('TypedDictModel', **field_definitions)
560564

561-
def typed_dict_validator(values: Dict[str, Any]) -> Dict[str, Any]:
565+
def typed_dict_validator(values: 'TypedDict') -> Dict[str, Any]:
562566
return TypedDictModel(**values).dict(exclude_unset=True)
563567

564568
return typed_dict_validator

0 commit comments

Comments
 (0)