|  | 
| 7 | 7 | from typing_extensions import get_origin | 
| 8 | 8 | from pydantic import ConfigDict, create_model | 
| 9 | 9 | from pydantic_core import from_json | 
| 10 |  | -from typing_inspect import is_optional_type | 
|  | 10 | +from typing_inspection.typing_objects import is_union | 
| 11 | 11 | 
 | 
| 12 | 12 | from ..types.basemodel import BaseModel, Nullable, OptionalNullable, Unset | 
| 13 | 13 | 
 | 
| 14 | 14 | 
 | 
| 15 | 15 | def serialize_decimal(as_str: bool): | 
| 16 | 16 |     def serialize(d): | 
| 17 |  | -        if is_optional_type(type(d)) and d is None: | 
|  | 17 | +        # Optional[T] is a Union[T, None] | 
|  | 18 | +        if is_union(type(d)) and type(None) in get_args(type(d)) and d is None: | 
| 18 | 19 |             return None | 
| 19 | 20 |         if isinstance(d, Unset): | 
| 20 | 21 |             return d | 
| @@ -42,7 +43,8 @@ def validate_decimal(d): | 
| 42 | 43 | 
 | 
| 43 | 44 | def serialize_float(as_str: bool): | 
| 44 | 45 |     def serialize(f): | 
| 45 |  | -        if is_optional_type(type(f)) and f is None: | 
|  | 46 | +        # Optional[T] is a Union[T, None] | 
|  | 47 | +        if is_union(type(f)) and type(None) in get_args(type(f)) and f is None: | 
| 46 | 48 |             return None | 
| 47 | 49 |         if isinstance(f, Unset): | 
| 48 | 50 |             return f | 
| @@ -70,7 +72,8 @@ def validate_float(f): | 
| 70 | 72 | 
 | 
| 71 | 73 | def serialize_int(as_str: bool): | 
| 72 | 74 |     def serialize(i): | 
| 73 |  | -        if is_optional_type(type(i)) and i is None: | 
|  | 75 | +        # Optional[T] is a Union[T, None] | 
|  | 76 | +        if is_union(type(i)) and type(None) in get_args(type(i)) and i is None: | 
| 74 | 77 |             return None | 
| 75 | 78 |         if isinstance(i, Unset): | 
| 76 | 79 |             return i | 
| @@ -118,7 +121,8 @@ def validate(e): | 
| 118 | 121 | 
 | 
| 119 | 122 | def validate_const(v): | 
| 120 | 123 |     def validate(c): | 
| 121 |  | -        if is_optional_type(type(c)) and c is None: | 
|  | 124 | +        # Optional[T] is a Union[T, None] | 
|  | 125 | +        if is_union(type(c)) and type(None) in get_args(type(c)) and c is None: | 
| 122 | 126 |             return None | 
| 123 | 127 | 
 | 
| 124 | 128 |         if v != c: | 
|  | 
0 commit comments