From 0ebca5883ea310d66abb6f9a7a05172d64d065c9 Mon Sep 17 00:00:00 2001 From: Mehdi Date: Sat, 9 Feb 2019 17:13:54 +0100 Subject: [PATCH 1/2] Fix JSON type: json can either be a Dict or a List --- sqlalchemy-stubs/sql/sqltypes.pyi | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sqlalchemy-stubs/sql/sqltypes.pyi b/sqlalchemy-stubs/sql/sqltypes.pyi index 7f41b9d..bc4c804 100644 --- a/sqlalchemy-stubs/sql/sqltypes.pyi +++ b/sqlalchemy-stubs/sql/sqltypes.pyi @@ -243,7 +243,9 @@ class Interval(Emulated, _AbstractInterval[timedelta], TypeDecorator[timedelta]) def bind_processor(self, dialect: Dialect) -> Callable[[Optional[timedelta]], str]: ... def result_processor(self, dialect: Dialect, coltype: Any) -> Callable[[Optional[str]], Optional[timedelta]]: ... -class JSON(Indexable, TypeEngine[Dict[str, Any]]): +_JSONT = Union[Dict[str, Any], List[Any]] + +class JSON(Indexable, TypeEngine[_JSONT]): __visit_name__: str = ... hashable: bool = ... NULL: util.symbol = ... @@ -257,12 +259,13 @@ class JSON(Indexable, TypeEngine[Dict[str, Any]]): class JSONIndexType(JSONElementType): ... class JSONPathType(JSONElementType): ... comparator_factory: Type[Any] = ... + # This method returns `dict`, but it seems to be a bug in SQLAlchemy. @property def python_type(self) -> Type[Dict[str, Any]]: ... @property def should_evaluate_none(self) -> bool: ... # type: ignore # incompatible with supertype "TypeEngine" - def bind_processor(self, dialect: Dialect) -> Callable[[Optional[Dict[str, Any]]], Optional[str]]: ... - def result_processor(self, dialect: Dialect, coltype: Any) -> Callable[[Optional[str]], Optional[Dict[str, Any]]]: ... + def bind_processor(self, dialect: Dialect) -> Callable[[Optional[_JSONT]], Optional[str]]: ... + def result_processor(self, dialect: Dialect, coltype: Any) -> Callable[[Optional[str]], Optional[_JSONT]]: ... class ARRAY(Indexable, Concatenable, TypeEngine[List[_T]]): __visit_name__: str = ... From ad6551b45b4b902f3b6466851a1f1d46ff0f433d Mon Sep 17 00:00:00 2001 From: Mehdi Date: Sat, 9 Feb 2019 23:00:37 +0100 Subject: [PATCH 2/2] Add enums attribute to Enum --- sqlalchemy-stubs/sql/sqltypes.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/sqlalchemy-stubs/sql/sqltypes.pyi b/sqlalchemy-stubs/sql/sqltypes.pyi index bc4c804..aa8f094 100644 --- a/sqlalchemy-stubs/sql/sqltypes.pyi +++ b/sqlalchemy-stubs/sql/sqltypes.pyi @@ -172,6 +172,7 @@ class Enum(Emulated, String, SchemaType): native_enum: bool = ... create_constraint: bool = ... validate_strings: bool = ... + enums: List[typing_Text] = ... # This is set inside _setup_for_values. def __init__(self, *enums: Any, **kw: Any) -> None: ... @property def native(self) -> bool: ...