1616IS_PYDANTIC_V2 = pydantic .VERSION .startswith ("2." )
1717
1818if IS_PYDANTIC_V2 :
19+ UnionType : Any = getattr (types , "UnionType" , None )
1920 ModelField = Any
2021 encoders_by_type = {
2122 dt .date : str ,
@@ -37,7 +38,7 @@ def is_literal_type(type_: Any) -> bool:
3738 return get_origin (type_ ) in (typing .Literal , typing_extensions .Literal )
3839
3940 def is_union (type_ : Any ) -> bool :
40- return get_origin (type_ ) in (Union , types . UnionType )
41+ return get_origin (type_ ) in (Union , UnionType )
4142else :
4243 from pydantic .datetime_parse import parse_date as parse_date # type: ignore[no-redef]
4344 from pydantic .datetime_parse import parse_datetime as parse_datetime # type: ignore[no-redef]
@@ -209,10 +210,10 @@ class V2RootModel(UniversalBaseModel, pydantic.RootModel): # type: ignore[misc,
209210
210211
211212def encode_by_type (o : Any ) -> Any :
212- encoders_by_class_tuples : Dict [Callable [[Any ], Any ], Tuple [type [Any ], ...]] = {}
213+ encoders_by_class_tuples : Dict [Callable [[Any ], Any ], Tuple [Type [Any ], ...]] = {}
213214 for type_ , encoder in encoders_by_type .items ():
214215 typed_encoder = cast (Callable [[Any ], Any ], encoder )
215- typed_type = cast (type [Any ], type_ )
216+ typed_type = cast (Type [Any ], type_ )
216217 encoders_by_class_tuples [typed_encoder ] = encoders_by_class_tuples .get (typed_encoder , ()) + (typed_type ,)
217218
218219 if type (o ) in encoders_by_type :
0 commit comments