1- from typing import Any , Dict , List , Type , TypeVar , cast , get_args
1+ from typing import Any , Dict , List , Optional , Type , TypeVar , Union , cast , get_args
22
33from pydantic import BaseModel
44from sqlalchemy import types
@@ -13,7 +13,7 @@ class AutoString(types.TypeDecorator): # type: ignore
1313 cache_ok = True
1414 mysql_default_length = 255
1515
16- def load_dialect_impl (self , dialect : Dialect ) -> " types.TypeEngine[Any]" :
16+ def load_dialect_impl (self , dialect : Dialect ) -> types .TypeEngine [Any ]:
1717 impl = cast (types .String , self .impl )
1818 if impl .length is None and dialect .name == "mysql" :
1919 return dialect .type_descriptor (types .String (self .mysql_default_length ))
@@ -28,16 +28,20 @@ class PydanticJSONB(types.TypeDecorator): # type: ignore
2828
2929 def __init__ (
3030 self ,
31- model_class : Type [BaseModelType ]
32- | Type [list [BaseModelType ]]
33- | Type [Dict [str , BaseModelType ]],
34- * args ,
35- ** kwargs ,
31+ model_class : Union [
32+ Type [BaseModelType ],
33+ Type [List [BaseModelType ]],
34+ Type [Dict [str , BaseModelType ]],
35+ ],
36+ * args : Any ,
37+ ** kwargs : Any ,
3638 ):
3739 super ().__init__ (* args , ** kwargs )
3840 self .model_class = model_class # Pydantic model class to use
3941
40- def process_bind_param (self , value : Any , dialect ) -> dict | list [dict ] | None : # noqa: ANN401, ARG002, ANN001
42+ def process_bind_param (
43+ self , value : Any , dialect : Any
44+ ) -> Optional [Union [Dict [str , Any ], List [Dict [str , Any ]]]]: # noqa: ANN401, ARG002, ANN001
4145 if value is None :
4246 return None
4347 if isinstance (value , BaseModel ):
@@ -55,8 +59,8 @@ def process_bind_param(self, value: Any, dialect) -> dict | list[dict] | None:
5559 return value
5660
5761 def process_result_value (
58- self , value : Any , dialect
59- ) -> BaseModelType | List [BaseModelType ] | Dict [str , BaseModelType ] | None : # noqa: ANN401, ARG002, ANN001
62+ self , value : Any , dialect : Any
63+ ) -> Optional [ Union [ BaseModelType , List [BaseModelType ], Dict [str , BaseModelType ]]] : # noqa: ANN401, ARG002, ANN001
6064 if value is None :
6165 return None
6266 if isinstance (value , dict ):
0 commit comments