Skip to content

Commit e957d11

Browse files
committed
feat(pydantic_partial): ✨ Better type checks + support UnionType
1 parent a39b984 commit e957d11

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pydantic_partial/partial.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class Something(PartialModelMixin, pydantic.BaseModel):
2828
import warnings
2929
from typing import Any, Optional, TypeVar, Union, cast, get_args, get_origin
3030

31+
try:
32+
from types import UnionType
33+
except ImportError:
34+
UnionType = Union
35+
3136
import pydantic
3237

3338
from ._compat import NULLABLE_KWARGS, PydanticCompat
@@ -90,7 +95,7 @@ def _partial_annotation_arg(field_name_: str, field_annotation: type) -> type:
9095
# Change type for sub models, if requested
9196
if recursive or sub_fields_requested:
9297
field_annotation_origin = get_origin(field_annotation)
93-
if field_annotation_origin in (Union, list, tuple, tuple, list, dict, dict):
98+
if field_annotation_origin in (Union, UnionType, tuple, list, set, dict):
9499
field_annotation = field_annotation_origin[ # type: ignore
95100
tuple(
96101
_partial_annotation_arg(field_name, field_annotation_arg)

0 commit comments

Comments
 (0)