1- from typing import Any , cast , Optional
1+ from typing import Any , cast , Optional , TypeVar
22from enum import IntEnum as _IntEnum
33
44from sqlalchemy import types
55from sqlalchemy .engine .interfaces import Dialect
66
77
8+ _TIntEnum = TypeVar ('_TIntEnum' , bound = "_IntEnum" )
9+
10+
811class AutoString (types .TypeDecorator ): # type: ignore
912 impl = types .String
1013 cache_ok = True
@@ -43,7 +46,7 @@ class IntEnum(types.TypeDecorator): # type: ignore
4346
4447 impl = types .Integer
4548
46- def __init__ (self , enum_type : _IntEnum , * args , ** kwargs ):
49+ def __init__ (self , enum_type : _TIntEnum , * args , ** kwargs ):
4750 super ().__init__ (* args , ** kwargs )
4851
4952 # validate the input enum type
@@ -54,15 +57,15 @@ def __init__(self, enum_type: _IntEnum, *args, **kwargs):
5457
5558 self .enum_type = enum_type
5659
57- def process_result_value (self , value : Optional [int ], dialect ) -> Optional [_IntEnum ]:
60+ def process_result_value (self , value : Optional [int ], dialect : Dialect ) -> Optional [_TIntEnum ]:
5861
5962 if value is None :
6063 return None
6164
6265 result = self .enum_type (value )
6366 return result
6467
65- def process_bind_param (self , value : Optional [_IntEnum ], dialect ) -> Optional [int ]:
68+ def process_bind_param (self , value : Optional [_TIntEnum ], dialect : Dialect ) -> Optional [int ]:
6669
6770 if value is None :
6871 return None
0 commit comments