Skip to content

Commit 638b850

Browse files
mehdigmirailevkivskyi
authored andcommitted
Fix JSON type + update Enum (#72)
* The JSON type can also be a list, and is not restricted to a dict. * Added the `enums` attribute to `Enum` class
1 parent adc1c47 commit 638b850

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

sqlalchemy-stubs/sql/sqltypes.pyi

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class Enum(Emulated, String, SchemaType):
172172
native_enum: bool = ...
173173
create_constraint: bool = ...
174174
validate_strings: bool = ...
175+
enums: List[typing_Text] = ... # This is set inside _setup_for_values.
175176
def __init__(self, *enums: Any, **kw: Any) -> None: ...
176177
@property
177178
def native(self) -> bool: ...
@@ -243,7 +244,9 @@ class Interval(Emulated, _AbstractInterval[timedelta], TypeDecorator[timedelta])
243244
def bind_processor(self, dialect: Dialect) -> Callable[[Optional[timedelta]], str]: ...
244245
def result_processor(self, dialect: Dialect, coltype: Any) -> Callable[[Optional[str]], Optional[timedelta]]: ...
245246

246-
class JSON(Indexable, TypeEngine[Dict[str, Any]]):
247+
_JSONT = Union[Dict[str, Any], List[Any]]
248+
249+
class JSON(Indexable, TypeEngine[_JSONT]):
247250
__visit_name__: str = ...
248251
hashable: bool = ...
249252
NULL: util.symbol = ...
@@ -257,12 +260,13 @@ class JSON(Indexable, TypeEngine[Dict[str, Any]]):
257260
class JSONIndexType(JSONElementType): ...
258261
class JSONPathType(JSONElementType): ...
259262
comparator_factory: Type[Any] = ...
263+
# This method returns `dict`, but it seems to be a bug in SQLAlchemy.
260264
@property
261265
def python_type(self) -> Type[Dict[str, Any]]: ...
262266
@property
263267
def should_evaluate_none(self) -> bool: ... # type: ignore # incompatible with supertype "TypeEngine"
264-
def bind_processor(self, dialect: Dialect) -> Callable[[Optional[Dict[str, Any]]], Optional[str]]: ...
265-
def result_processor(self, dialect: Dialect, coltype: Any) -> Callable[[Optional[str]], Optional[Dict[str, Any]]]: ...
268+
def bind_processor(self, dialect: Dialect) -> Callable[[Optional[_JSONT]], Optional[str]]: ...
269+
def result_processor(self, dialect: Dialect, coltype: Any) -> Callable[[Optional[str]], Optional[_JSONT]]: ...
266270

267271
class ARRAY(Indexable, Concatenable, TypeEngine[List[_T]]):
268272
__visit_name__: str = ...

0 commit comments

Comments
 (0)