From 0d603978b27169c5ba58e90ba9c2a7b14aa07c95 Mon Sep 17 00:00:00 2001 From: Alex Riina Date: Fri, 6 Mar 2020 21:07:02 -0500 Subject: [PATCH 01/33] Add missing types to Session --- sqlalchemy-stubs/orm/session.pyi | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sqlalchemy-stubs/orm/session.pyi b/sqlalchemy-stubs/orm/session.pyi index d5f3f47..ea79d7c 100644 --- a/sqlalchemy-stubs/orm/session.pyi +++ b/sqlalchemy-stubs/orm/session.pyi @@ -44,8 +44,8 @@ class Session(_SessionClassMethods): def info(self): ... def begin(self, subtransactions: bool = ..., nested: bool = ...) -> SessionTransaction: ... def begin_nested(self) -> SessionTransaction: ... - def rollback(self): ... - def commit(self): ... + def rollback(self) -> None: ... + def commit(self) -> None: ... def prepare(self): ... def connection(self, mapper: Optional[Any] = ..., clause: Optional[Any] = ..., bind: Optional[Any] = ..., close_with_result: bool = ..., @@ -54,8 +54,8 @@ class Session(_SessionClassMethods): mapper: Optional[Any] = ..., bind: Optional[Any] = ..., **kw): ... def scalar(self, clause, params: Optional[Any] = ..., mapper: Optional[Any] = ..., bind: Optional[Any] = ..., **kw): ... - def close(self): ... - def invalidate(self): ... + def close(self) -> None: ... + def invalidate(self) -> None: ... def expunge_all(self): ... def bind_mapper(self, mapper, bind): ... def bind_table(self, table, bind): ... @@ -64,24 +64,24 @@ class Session(_SessionClassMethods): @property def no_autoflush(self): ... def refresh(self, instance, attribute_names: Optional[Any] = ..., lockmode: Optional[Any] = ...): ... - def expire_all(self): ... - def expire(self, instance, attribute_names: Optional[Any] = ...): ... + def expire_all(self) -> None: ... + def expire(self, instance, attribute_names: Optional[Any] = ...) -> None: ... def prune(self): ... def expunge(self, instance): ... - def add(self, instance, _warn: bool = ...): ... - def add_all(self, instances): ... + def add(self, instance, _warn: bool = ...) -> None: ... + def add_all(self, instances) -> None: ... def delete(self, instance): ... def merge(self, instance, load: bool = ...): ... def enable_relationship_loading(self, obj): ... def __contains__(self, instance): ... def __iter__(self): ... - def flush(self, objects: Optional[Any] = ...): ... + def flush(self, objects: Optional[Any] = ...) -> None: ... def bulk_save_objects(self, objects, return_defaults: bool = ..., update_changed_only: bool = ...): ... def bulk_insert_mappings(self, mapper, mappings, return_defaults: bool = ..., render_nulls: bool = ...): ... def bulk_update_mappings(self, mapper, mappings): ... def is_modified(self, instance, include_collections: bool = ..., passive: bool = ...): ... @property - def is_active(self): ... + def is_active(self) -> bool: ... @property def dirty(self): ... @property From e2e9c28fc966415da6f8081d5945f48e69f8b61b Mon Sep 17 00:00:00 2001 From: Boryslav Larin Date: Wed, 8 Apr 2020 13:23:22 +0300 Subject: [PATCH 02/33] Allow List as param to any_ --- sqlalchemy-stubs/sql/elements.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sqlalchemy-stubs/sql/elements.pyi b/sqlalchemy-stubs/sql/elements.pyi index cb9a64f..ef29591 100644 --- a/sqlalchemy-stubs/sql/elements.pyi +++ b/sqlalchemy-stubs/sql/elements.pyi @@ -298,6 +298,9 @@ class CollectionAggregate(UnaryExpression[_T]): @overload @classmethod def _create_any(cls, expr: ClauseElement) -> CollectionAggregate[Any]: ... + @overload + @classmethod + def _create_any(cls, expr: List[Any]) -> CollectionAggregate[Any]: ... _AB = TypeVar('_AB', bound=AsBoolean) From 5e33374f43171c6d6768a056840978020427f328 Mon Sep 17 00:00:00 2001 From: Boryslav Larin Date: Wed, 15 Apr 2020 11:14:11 +0300 Subject: [PATCH 03/33] Add missing orderinglist funcs --- sqlalchemy-stubs/ext/orderinglist.pyi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sqlalchemy-stubs/ext/orderinglist.pyi b/sqlalchemy-stubs/ext/orderinglist.pyi index 65387ad..48347c4 100644 --- a/sqlalchemy-stubs/ext/orderinglist.pyi +++ b/sqlalchemy-stubs/ext/orderinglist.pyi @@ -1,10 +1,13 @@ -from typing import Any, Optional +from typing import Any, Optional, Callable def ordering_list(attr, count_from: Optional[Any] = ..., **kw): ... +def count_from_1(index: int, collection: Any) -> Any: ... +def count_from_0(index: int, collection: Any) -> Any: ... +def count_from_n_factory(start: int) -> Callable[[int, Any], Any]: ... class OrderingList(list): ordering_attr: str = ... - ordering_func: Any = ... + ordering_func: Callable[[int, Any], Any] = ... reorder_on_append: Any = ... def __init__(self, ordering_attr: Optional[str] = ..., ordering_func: Optional[Any] = ..., reorder_on_append: bool = ...) -> None: ... From ae180c903b5bb9a5ece56fc1872af49c69499052 Mon Sep 17 00:00:00 2001 From: Boryslav Larin Date: Thu, 16 Apr 2020 16:58:35 +0300 Subject: [PATCH 04/33] Use Iterable instead of List for any_ param --- sqlalchemy-stubs/sql/elements.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlalchemy-stubs/sql/elements.pyi b/sqlalchemy-stubs/sql/elements.pyi index ef29591..b38f0f9 100644 --- a/sqlalchemy-stubs/sql/elements.pyi +++ b/sqlalchemy-stubs/sql/elements.pyi @@ -300,7 +300,7 @@ class CollectionAggregate(UnaryExpression[_T]): def _create_any(cls, expr: ClauseElement) -> CollectionAggregate[Any]: ... @overload @classmethod - def _create_any(cls, expr: List[Any]) -> CollectionAggregate[Any]: ... + def _create_any(cls, expr: Iterable[Any]) -> CollectionAggregate[Any]: ... _AB = TypeVar('_AB', bound=AsBoolean) From 9d172011537167588027e8f86bf9c65e0018744d Mon Sep 17 00:00:00 2001 From: Boryslav Larin Date: Tue, 26 May 2020 13:30:16 +0300 Subject: [PATCH 05/33] MapperExtension added to stubs --- sqlalchemy-stubs/orm/__init__.pyi | 23 +++++++++++++++++++++++ sqlalchemy-stubs/util/langhelpers.pyi | 5 +++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/sqlalchemy-stubs/orm/__init__.pyi b/sqlalchemy-stubs/orm/__init__.pyi index 1d45e02..fc5640c 100644 --- a/sqlalchemy-stubs/orm/__init__.pyi +++ b/sqlalchemy-stubs/orm/__init__.pyi @@ -1,4 +1,5 @@ from typing import Any, Optional +from ..util.langhelpers import symbol from .mapper import ( Mapper as Mapper, class_mapper as class_mapper, @@ -88,3 +89,25 @@ def eagerload(*args, **kwargs): ... def eagerload_all(*args, **kwargs): ... contains_alias = AliasOption + + +class MapperExtension: + @classmethod + def _adapt_instrument_class(cls, self, listener) -> None: ... + + @classmethod + def _adapt_listener(cls, self, listener) -> None: ... + + @classmethod + def _adapt_listener_methods(cls, self, listener, methods) -> None: ... + + def instrument_class(self, mapper, class_) -> symbol: ... + def init_instance(self, mapper, class_, oldinit, instance, args, kwargs) -> symbol: ... + def init_failed(self, mapper, class_, oldinit, instance, args, kwargs) -> symbol: ... + def reconstruct_instance(self, mapper, instance) -> symbol: ... + def before_insert(self, mapper, connection, instance) -> symbol: ... + def after_insert(self, mapper, connection, instance) -> symbol: ... + def before_update(self, mapper, connection, instance) -> symbol: ... + def after_update(self, mapper, connection, instance) -> symbol: ... + def before_delete(self, mapper, connection, instance) -> symbol: ... + def after_delete(self, mapper, connection, instance) -> symbol: ... \ No newline at end of file diff --git a/sqlalchemy-stubs/util/langhelpers.pyi b/sqlalchemy-stubs/util/langhelpers.pyi index c1147be..1092f45 100644 --- a/sqlalchemy-stubs/util/langhelpers.pyi +++ b/sqlalchemy-stubs/util/langhelpers.pyi @@ -1,4 +1,4 @@ -from typing import Any, Optional +from typing import Any, Optional, Dict, TypeVar def md5_hex(x): ... @@ -97,8 +97,9 @@ class hybridmethod(object): def __init__(self, func) -> None: ... def __get__(self, instance, owner): ... +T = TypeVar('T', bound='symbol') class symbol(object): - symbols: Any = ... + symbols: Dict[str, 'T'] def __new__(cls, name, doc: Optional[Any] = ..., canonical: Optional[Any] = ...): ... def set_creation_order(instance): ... From 0e3897c2074f3f64b7d690166ee5b77eba61b705 Mon Sep 17 00:00:00 2001 From: Boryslav Larin Date: Tue, 26 May 2020 15:46:04 +0300 Subject: [PATCH 06/33] Set args parametr for Table.__init__ --- sqlalchemy-stubs/sql/schema.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sqlalchemy-stubs/sql/schema.pyi b/sqlalchemy-stubs/sql/schema.pyi index 758ab4b..d424a0d 100644 --- a/sqlalchemy-stubs/sql/schema.pyi +++ b/sqlalchemy-stubs/sql/schema.pyi @@ -6,10 +6,11 @@ from . import visitors, functions from .base import SchemaEventTarget as SchemaEventTarget, DialectKWArgs as DialectKWArgs, ColumnCollection from .elements import ColumnClause as ColumnClause, TextClause, ColumnElement from .selectable import TableClause as TableClause -from .type_api import TypeEngine +from .type_api import TypeEngine, TypeDecorator, Variant from .. import util from ..engine import Engine, Connection, Connectable from ..engine.url import URL +from ..dialects.postgres.array import ARRAY from .compiler import DDLCompiler from .expression import FunctionElement import threading @@ -42,7 +43,7 @@ class Table(DialectKWArgs, SchemaItem, TableClause): # type: ignore def __new__(cls, *args, **kw): ... @property def quote_schema(self) -> Optional[bool]: ... - def __init__(self, name: str, metadata: MetaData, *args: Any, autoload: bool = ..., autoload_replace: bool = ..., + def __init__(self, name: str, metadata: MetaData, *args: SchemaItem, autoload: bool = ..., autoload_replace: bool = ..., autoload_with: Union[Engine, Connection] = ..., extend_existing: bool = ..., implicit_returning: bool = ..., include_columns: SequenceType[str] = ..., info: Mapping[str, Any] = ..., keep_existing: bool = ..., listeners: SequenceType[Tuple[str, Callable[..., Any]]] = ..., mustexist: bool = ..., From fbe508d13248bd7211929ae944a6f1135e842d91 Mon Sep 17 00:00:00 2001 From: Boryslav Larin Date: Thu, 28 May 2020 16:40:25 +0300 Subject: [PATCH 07/33] Fix tests --- sqlalchemy-stubs/orm/__init__.pyi | 21 ++++++++++----------- sqlalchemy-stubs/sql/schema.pyi | 3 +-- sqlalchemy-stubs/util/langhelpers.pyi | 3 +-- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/sqlalchemy-stubs/orm/__init__.pyi b/sqlalchemy-stubs/orm/__init__.pyi index fc5640c..cfad9bf 100644 --- a/sqlalchemy-stubs/orm/__init__.pyi +++ b/sqlalchemy-stubs/orm/__init__.pyi @@ -1,5 +1,4 @@ from typing import Any, Optional -from ..util.langhelpers import symbol from .mapper import ( Mapper as Mapper, class_mapper as class_mapper, @@ -101,13 +100,13 @@ class MapperExtension: @classmethod def _adapt_listener_methods(cls, self, listener, methods) -> None: ... - def instrument_class(self, mapper, class_) -> symbol: ... - def init_instance(self, mapper, class_, oldinit, instance, args, kwargs) -> symbol: ... - def init_failed(self, mapper, class_, oldinit, instance, args, kwargs) -> symbol: ... - def reconstruct_instance(self, mapper, instance) -> symbol: ... - def before_insert(self, mapper, connection, instance) -> symbol: ... - def after_insert(self, mapper, connection, instance) -> symbol: ... - def before_update(self, mapper, connection, instance) -> symbol: ... - def after_update(self, mapper, connection, instance) -> symbol: ... - def before_delete(self, mapper, connection, instance) -> symbol: ... - def after_delete(self, mapper, connection, instance) -> symbol: ... \ No newline at end of file + def instrument_class(self, mapper, class_) -> Any: ... + def init_instance(self, mapper, class_, oldinit, instance, args, kwargs) -> Any: ... + def init_failed(self, mapper, class_, oldinit, instance, args, kwargs) -> Any: ... + def reconstruct_instance(self, mapper, instance) -> Any: ... + def before_insert(self, mapper, connection, instance) -> Any: ... + def after_insert(self, mapper, connection, instance) -> Any: ... + def before_update(self, mapper, connection, instance) -> Any: ... + def after_update(self, mapper, connection, instance) -> Any: ... + def before_delete(self, mapper, connection, instance) -> Any: ... + def after_delete(self, mapper, connection, instance) -> Any: ... \ No newline at end of file diff --git a/sqlalchemy-stubs/sql/schema.pyi b/sqlalchemy-stubs/sql/schema.pyi index d424a0d..e2ad747 100644 --- a/sqlalchemy-stubs/sql/schema.pyi +++ b/sqlalchemy-stubs/sql/schema.pyi @@ -10,7 +10,6 @@ from .type_api import TypeEngine, TypeDecorator, Variant from .. import util from ..engine import Engine, Connection, Connectable from ..engine.url import URL -from ..dialects.postgres.array import ARRAY from .compiler import DDLCompiler from .expression import FunctionElement import threading @@ -43,7 +42,7 @@ class Table(DialectKWArgs, SchemaItem, TableClause): # type: ignore def __new__(cls, *args, **kw): ... @property def quote_schema(self) -> Optional[bool]: ... - def __init__(self, name: str, metadata: MetaData, *args: SchemaItem, autoload: bool = ..., autoload_replace: bool = ..., + def __init__(self, name: str, metadata: MetaData, *args: Any, autoload: bool = ..., autoload_replace: bool = ..., autoload_with: Union[Engine, Connection] = ..., extend_existing: bool = ..., implicit_returning: bool = ..., include_columns: SequenceType[str] = ..., info: Mapping[str, Any] = ..., keep_existing: bool = ..., listeners: SequenceType[Tuple[str, Callable[..., Any]]] = ..., mustexist: bool = ..., diff --git a/sqlalchemy-stubs/util/langhelpers.pyi b/sqlalchemy-stubs/util/langhelpers.pyi index 1092f45..6d4e9b4 100644 --- a/sqlalchemy-stubs/util/langhelpers.pyi +++ b/sqlalchemy-stubs/util/langhelpers.pyi @@ -97,9 +97,8 @@ class hybridmethod(object): def __init__(self, func) -> None: ... def __get__(self, instance, owner): ... -T = TypeVar('T', bound='symbol') class symbol(object): - symbols: Dict[str, 'T'] + symbols: Dict[str, Any] def __new__(cls, name, doc: Optional[Any] = ..., canonical: Optional[Any] = ...): ... def set_creation_order(instance): ... From 853f6d80b2e4ea21d9b3a59e625f2c9b6f6bc8d3 Mon Sep 17 00:00:00 2001 From: "v.haritonskiy" Date: Fri, 15 Jan 2021 07:27:58 +0200 Subject: [PATCH 08/33] add parents property to mutablebase --- sqlalchemy-stubs/ext/mutable.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sqlalchemy-stubs/ext/mutable.pyi b/sqlalchemy-stubs/ext/mutable.pyi index f68846b..375b96c 100644 --- a/sqlalchemy-stubs/ext/mutable.pyi +++ b/sqlalchemy-stubs/ext/mutable.pyi @@ -1,6 +1,8 @@ class MutableBase(object): @classmethod def coerce(cls, key, value): ... + @property + def _parents(self): ... class Mutable(MutableBase): def changed(self): ... From 6e76aaed0e648badc67a514cc2667ceec9355900 Mon Sep 17 00:00:00 2001 From: wouter bolsterlee Date: Fri, 8 Jan 2021 12:42:46 +0100 Subject: [PATCH 09/33] Allow bool or string for relationship(passive_deletes=...) arg (#143) The relationship(passive_deletes=...) can be either a boolean or a string: https://docs.sqlalchemy.org/en/13/orm/relationship_api.html#sqlalchemy.orm.relationship.params.passive_deletes --- sqlalchemy-stubs/orm/relationships.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlalchemy-stubs/orm/relationships.pyi b/sqlalchemy-stubs/orm/relationships.pyi index d334b41..4627755 100644 --- a/sqlalchemy-stubs/orm/relationships.pyi +++ b/sqlalchemy-stubs/orm/relationships.pyi @@ -31,7 +31,7 @@ class RelationshipProperty(StrategizedProperty, Generic[_T_co]): lazy: Any = ... single_parent: bool = ... collection_class: Any = ... - passive_deletes: bool = ... + passive_deletes: Union[bool, str] = ... cascade_backrefs: bool = ... passive_updates: bool = ... remote_side: Any = ... @@ -61,7 +61,7 @@ class RelationshipProperty(StrategizedProperty, Generic[_T_co]): back_populates: Optional[Any] = ..., post_update: bool = ..., cascade: Union[str, bool] = ..., extension: Optional[Any] = ..., viewonly: bool = ..., lazy: Optional[Union[str, bool]] = ..., collection_class: Optional[Any] = ..., - passive_deletes: bool = ..., passive_updates: bool = ..., + passive_deletes: Union[bool, str] = ..., passive_updates: bool = ..., remote_side: Optional[Any] = ..., enable_typechecks: bool = ..., join_depth: Optional[Any] = ..., comparator_factory: Optional[Any] = ..., single_parent: bool = ..., innerjoin: bool = ..., distinct_target_key: Optional[Any] = ..., From 59a508d028972844ab8ec621fb9561b7b6a3e217 Mon Sep 17 00:00:00 2001 From: "item4(Kim Jin Su)" Date: Fri, 8 Jan 2021 20:50:41 +0900 Subject: [PATCH 10/33] Update spec of sqlalchemy.ext.hybrid.hybrid_property (#142) --- sqlalchemy-stubs/ext/hybrid.pyi | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sqlalchemy-stubs/ext/hybrid.pyi b/sqlalchemy-stubs/ext/hybrid.pyi index 1e5a214..c3ec573 100644 --- a/sqlalchemy-stubs/ext/hybrid.pyi +++ b/sqlalchemy-stubs/ext/hybrid.pyi @@ -19,16 +19,28 @@ class hybrid_property(interfaces.InspectionAttrInfo): fget: Any = ... fset: Any = ... fdel: Any = ... + custom_comparator: Any = ... + update_expr: Any = ... def __init__(self, fget, fset: Optional[Any] = ..., fdel: Optional[Any] = ..., - expr: Optional[Any] = ...) -> None: ... + expr: Optional[Any] = ..., custom_comparator: Optional[Any] = ..., + update_expr: Optional[Any] = ...) -> None: ... def __get__(self, instance, owner): ... def __set__(self, instance, value): ... def __delete__(self, instance): ... + def getter(self, fget): ... def setter(self, fset): ... def deleter(self, fdel): ... expr: Any = ... def expression(self, expr): ... def comparator(self, comparator): ... + def update_expression(self, meth): ... + def _copy(self, **kw): ... + def _expr_comparator(self): ... + def _get_expr(self, expr): ... + def _get_comparator(self, comparator): ... + @property + def overrides(self): ... + class Comparator(interfaces.PropComparator): property: Any = ... From ecf0f6e694dd16a08409cdd8edd2a7bf7462b501 Mon Sep 17 00:00:00 2001 From: Dean Way Date: Fri, 8 Jan 2021 12:54:24 +0100 Subject: [PATCH 11/33] Session merge should an object of the type passed (#165) See: https://docs.sqlalchemy.org/en/13/orm/session_api.html#sqlalchemy.orm.session.Session.merge Quote: ... The state of each attribute on the source instance is then copied to the target instance. The resulting target instance is then returned by the method ... --- sqlalchemy-stubs/orm/session.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlalchemy-stubs/orm/session.pyi b/sqlalchemy-stubs/orm/session.pyi index 87d7f40..0784df2 100644 --- a/sqlalchemy-stubs/orm/session.pyi +++ b/sqlalchemy-stubs/orm/session.pyi @@ -79,7 +79,7 @@ class Session(_SessionClassMethods): def add(self, instance, _warn: bool = ...) -> None: ... def add_all(self, instances) -> None: ... def delete(self, instance): ... - def merge(self, instance, load: bool = ...): ... + def merge(self, instance: _T, load: bool = ...) -> _T: ... def enable_relationship_loading(self, obj): ... def __contains__(self, instance): ... def __iter__(self): ... From a928eb97e28b1963990f646452ba6d2ceaf26a31 Mon Sep 17 00:00:00 2001 From: Keigo Kawamura Date: Fri, 8 Jan 2021 20:55:29 +0900 Subject: [PATCH 12/33] Update external/mypy to 0.790 (#179) Co-authored-by: Keigo Kawamura --- external/mypy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/mypy b/external/mypy index d9dea5f..69a055a 160000 --- a/external/mypy +++ b/external/mypy @@ -1 +1 @@ -Subproject commit d9dea5f3ad30bb449e4167b3e8476684ded0482e +Subproject commit 69a055a7632e2444fcb2bfb022d04f4546358d50 From f0ee59c65ac92f0b38dd6703e399158b5b47dcb8 Mon Sep 17 00:00:00 2001 From: Tero Vuotila Date: Fri, 8 Jan 2021 14:05:45 +0200 Subject: [PATCH 13/33] Add type stub for sqlalchemy.orm.session.close_all_sessions (#147) Related code in sqlalchemy repository: https://github.com/sqlalchemy/sqlalchemy/blob/ceba13d4be5e73fed4522d6f66ab4c54f60fd983/lib/sqlalchemy/orm/session.py#L3340-L3355 https://github.com/sqlalchemy/sqlalchemy/blob/ceba13d4be5e73fed4522d6f66ab4c54f60fd983/lib/sqlalchemy/orm/__init__.py#L40 --- sqlalchemy-stubs/orm/__init__.pyi | 1 + sqlalchemy-stubs/orm/session.pyi | 1 + 2 files changed, 2 insertions(+) diff --git a/sqlalchemy-stubs/orm/__init__.pyi b/sqlalchemy-stubs/orm/__init__.pyi index cfad9bf..32fd569 100644 --- a/sqlalchemy-stubs/orm/__init__.pyi +++ b/sqlalchemy-stubs/orm/__init__.pyi @@ -31,6 +31,7 @@ from .descriptor_props import ( from .relationships import foreign as foreign, remote as remote from .session import ( Session as Session, + close_all_sessions as close_all_sessions, object_session as object_session, sessionmaker as sessionmaker, make_transient as make_transient, diff --git a/sqlalchemy-stubs/orm/session.pyi b/sqlalchemy-stubs/orm/session.pyi index 0784df2..cf2ccc2 100644 --- a/sqlalchemy-stubs/orm/session.pyi +++ b/sqlalchemy-stubs/orm/session.pyi @@ -109,3 +109,4 @@ class sessionmaker(_SessionClassMethods): def make_transient(instance) -> None: ... def make_transient_to_detached(instance) -> None: ... def object_session(instance): ... +def close_all_sessions() -> None: ... From 9eebfd33a9c4cbf8ec05e0dd4d1c62dc6feb6111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Fri, 8 Jan 2021 13:09:04 +0100 Subject: [PATCH 14/33] Type relationship as list (#154) Currently, the plugin types relationships with uselist as Iterable[X], but these relationships actually expose a list with list semantics, including .append(), assignments, etc. This PR updates the plugin to type those relationships with List[X] instead of Iterable[X]. Ref: https://docs.sqlalchemy.org/en/13/orm/relationship_api.html#sqlalchemy.orm.relationship.params.uselist Ref of usage with assignment: https://docs.sqlalchemy.org/en/13/orm/tutorial.html#working-with-related-objects Ref of usage with append: https://docs.sqlalchemy.org/en/13/orm/tutorial.html#building-a-many-to-many-relationship Note: I'm by no means expert in mypy internals and its plugins, I'm not 100% sure the usage of ctx.api.named_generic_type('builtins.list', [new_arg]) is correct here, but I see that seems to be how it's used by mypy: https://github.com/python/mypy/blob/master/mypy/plugins/ctypes.py#L158 --- sqlmypy.py | 4 ++-- test/test-data/sqlalchemy-plugin-features.test | 12 +++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/sqlmypy.py b/sqlmypy.py index 4f005e2..9ac38e5 100644 --- a/sqlmypy.py +++ b/sqlmypy.py @@ -396,10 +396,10 @@ class User(Base): # Something complex, stay silent for now. new_arg = AnyType(TypeOfAny.special_form) - # We figured out, the model type. Now check if we need to wrap it in Iterable + # We figured out, the model type. Now check if we need to wrap it in List if uselist_arg: if parse_bool(uselist_arg): - new_arg = ctx.api.named_generic_type('typing.Iterable', [new_arg]) + new_arg = ctx.api.named_generic_type('builtins.list', [new_arg]) else: if has_annotation: # If there is an annotation we use it as a source of truth. diff --git a/test/test-data/sqlalchemy-plugin-features.test b/test/test-data/sqlalchemy-plugin-features.test index c6ac7e7..fd826a9 100644 --- a/test/test-data/sqlalchemy-plugin-features.test +++ b/test/test-data/sqlalchemy-plugin-features.test @@ -131,7 +131,6 @@ Base = declarative_base() from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, Integer, String from sqlalchemy.orm import relationship, RelationshipProperty -from typing import Iterable Base = declarative_base() @@ -144,7 +143,7 @@ class User(Base): user = User() reveal_type(user.first_other) # N: Revealed type is 'main.Other*' -reveal_type(user.second_other) # N: Revealed type is 'typing.Iterable*[main.Other]' +reveal_type(user.second_other) # N: Revealed type is 'builtins.list*[main.Other]' class Other(Base): __tablename__ = 'other' @@ -155,7 +154,6 @@ class Other(Base): from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, Integer, String from sqlalchemy.orm import relationship, RelationshipProperty -from typing import Iterable Base = declarative_base() @@ -169,7 +167,7 @@ class User(Base): user = User() reveal_type(user.first_other) # N: Revealed type is 'main.Other*' -reveal_type(user.second_other) # N: Revealed type is 'typing.Iterable*[main.Other]' +reveal_type(user.second_other) # N: Revealed type is 'builtins.list*[main.Other]' class Other(Base): __tablename__ = 'other' @@ -180,7 +178,7 @@ class Other(Base): from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, Integer, String from sqlalchemy.orm import relationship, RelationshipProperty -from typing import Iterable +from typing import List Base = declarative_base() @@ -188,9 +186,9 @@ class User(Base): __tablename__ = 'users' id = Column(Integer(), primary_key=True) first_other: RelationshipProperty[Other] = relationship('Other') - second_other: RelationshipProperty[Iterable[Other]] = relationship(Other, uselist=True) + second_other: RelationshipProperty[List[Other]] = relationship(Other, uselist=True) third_other: RelationshipProperty[Other] = relationship(Other, uselist=False) - bad_other: RelationshipProperty[Other] = relationship('Other', uselist=True) # E: Incompatible types in assignment (expression has type "RelationshipProperty[Iterable[Other]]", variable has type "RelationshipProperty[Other]") + bad_other: RelationshipProperty[Other] = relationship('Other', uselist=True) # E: Incompatible types in assignment (expression has type "RelationshipProperty[List[Other]]", variable has type "RelationshipProperty[Other]") class Other(Base): __tablename__ = 'other' From 2ed8b7ee6ae7df822a707d6a47c109fd08488115 Mon Sep 17 00:00:00 2001 From: Phil Krylov Date: Fri, 8 Jan 2021 15:10:50 +0300 Subject: [PATCH 15/33] Add CTE prefixes (#157) https://github.com/sqlalchemy/sqlalchemy/pull/5043 added support for CTE prefix clauses in PostgreSQL 12. This PR fixes the dreadful `"CTE" has no attribute "prefix_with"` error for me. --- sqlalchemy-stubs/sql/selectable.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sqlalchemy-stubs/sql/selectable.pyi b/sqlalchemy-stubs/sql/selectable.pyi index 8d26bcc..74a5000 100644 --- a/sqlalchemy-stubs/sql/selectable.pyi +++ b/sqlalchemy-stubs/sql/selectable.pyi @@ -122,11 +122,12 @@ class TableSample(Alias): def __init__(self, selectable: FromClause, sampling: Union[float, Function[float]], name: Optional[str] = ..., seed: Optional[Any] = ...) -> None: ... -class CTE(Generative, HasSuffixes, Alias): +class CTE(Generative, HasPrefixes, HasSuffixes, Alias): __visit_name__: str = ... recursive: bool = ... def __init__(self, selectable: Select, name: Optional[str] = ..., recursive: bool = ..., - _cte_alias: Optional[Any] = ..., _restates: Any = ..., _suffixes: Optional[Any] = ...) -> None: ... + _cte_alias: Optional[Any] = ..., _restates: Any = ..., _prefixes: Optional[Any] = ..., + _suffixes: Optional[Any] = ...) -> None: ... def alias(self, name: Optional[str] = ..., flat: bool = ...) -> CTE: ... def union(self, other: Select) -> CTE: ... def union_all(self, other: Select) -> CTE: ... From 2bb7a552aafefb0cedf3d434591d26a942346596 Mon Sep 17 00:00:00 2001 From: David Andersson <51036209+jdkandersson@users.noreply.github.com> Date: Fri, 8 Jan 2021 23:12:12 +1100 Subject: [PATCH 16/33] Make name argument optional (#158) Closes #124 --- sqlalchemy-stubs/sql/schema.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlalchemy-stubs/sql/schema.pyi b/sqlalchemy-stubs/sql/schema.pyi index e2ad747..8532387 100644 --- a/sqlalchemy-stubs/sql/schema.pyi +++ b/sqlalchemy-stubs/sql/schema.pyi @@ -304,7 +304,7 @@ class Index(DialectKWArgs, ColumnCollectionMixin, SchemaItem): name: str = ... unique: bool = ... info: Optional[Mapping[str, Any]] = ... - def __init__(self, name: str, *expressions: Union[TextClause, ColumnElement[Any], str], unique: bool = ..., + def __init__(self, name: Optional[str], *expressions: Union[TextClause, ColumnElement[Any], str], unique: bool = ..., quote: Optional[bool] = ..., info: Optional[Mapping[str, Any]] = ..., **kw: Any) -> None: ... @property def bind(self) -> Optional[Union[Engine, Connection]]: ... From 8f25e2e3af3e3450d0fac7e3cd2440aa31fb2ac9 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Fri, 8 Jan 2021 12:12:45 +0000 Subject: [PATCH 17/33] Fix re-export of some names according to new PEP 484 rules (#198) This makes the stubs with mypy version 0.800 (to be released soon). Co-authored-by: Ivan Levkivskyi --- sqlalchemy-stubs/util/compat.pyi | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sqlalchemy-stubs/util/compat.pyi b/sqlalchemy-stubs/util/compat.pyi index c067690..bc3b24c 100644 --- a/sqlalchemy-stubs/util/compat.pyi +++ b/sqlalchemy-stubs/util/compat.pyi @@ -3,13 +3,19 @@ import builtins from typing import Any, Optional, Text import threading as threading from collections import namedtuple as namedtuple -from io import BytesIO as byte_buffer +from io import BytesIO from io import StringIO as StringIO from inspect import getargspec as inspect_getfullargspec -from operator import attrgetter as dottedgetter +from operator import attrgetter + +byte_buffer = BytesIO +dottedgetter = attrgetter + if sys.version_info < (3, 0): - from itertools import izip_longest as zip_longest - import cPickle as pickle + from itertools import izip_longest + zip_longest = izip_longest + import cPickle + pickle = cPickle from urllib import quote_plus as quote_plus, unquote_plus as unquote_plus, quote as quote, unquote as unquote from urlparse import parse_qsl as parse_qsl else: From 3941f827ed464c8a4cc2448aee2c239ecba01f0f Mon Sep 17 00:00:00 2001 From: Thijs Damsma Date: Fri, 8 Jan 2021 13:15:10 +0100 Subject: [PATCH 18/33] Test with python 3.8 (#186) Co-authored-by: Keigo Kawamura --- .travis.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8214c16..4e7b47e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,8 +23,13 @@ jobs: script: | set -e pytest + - name: "run test suite with python 3.8" + python: 3.8 + script: | + set -e + pytest - name: "run typecheck on stubs" - python: 3.7 + python: 3.8 script: | set -e mkdir tmpd @@ -32,11 +37,11 @@ jobs: cd tmpd python3 -m mypy -p sqlalchemy - name: "run flake8 on stubs" - python: 3.7 + python: 3.8 script: | flake8 sqlalchemy-stubs - name: "run typecheck on plugin" - python: 3.7 + python: 3.8 script: | set -e MYPYPATH=external/mypy python3 -m mypy --config-file external/mypy/mypy_self_check.ini sqlmypy.py From d1003efb96120d7dc7f052fa832b05b0dbec701d Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Fri, 8 Jan 2021 16:37:56 +0000 Subject: [PATCH 19/33] Fix single item query return type (#199) Co-authored-by: Ivan Levkivskyi --- sqlalchemy-stubs/orm/session.pyi | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sqlalchemy-stubs/orm/session.pyi b/sqlalchemy-stubs/orm/session.pyi index cf2ccc2..af3cbed 100644 --- a/sqlalchemy-stubs/orm/session.pyi +++ b/sqlalchemy-stubs/orm/session.pyi @@ -1,4 +1,4 @@ -from typing import Any, Optional, Type, TypeVar, Union, overload +from typing import Any, Optional, Tuple, Type, TypeVar, overload from sqlalchemy import Column from sqlalchemy.orm.query import Query @@ -66,9 +66,11 @@ class Session(_SessionClassMethods): def bind_table(self, table, bind): ... def get_bind(self, mapper: Optional[Any] = ..., clause: Optional[Any] = ...): ... @overload - def query(self, entity: Union[Type[_T], Column[_T]], **kwargs) -> Query[_T]: ... + def query(self, entity: Type[_T], **kwargs) -> Query[_T]: ... @overload - def query(self, *entities, **kwargs) -> Query: ... + def query(self, entity: Column[_T], **kwargs) -> Query[Tuple[_T]]: ... + @overload + def query(self, *entities, **kwargs) -> Query[Any]: ... # plugin is needed for precise type @property def no_autoflush(self): ... def refresh(self, instance, attribute_names: Optional[Any] = ..., lockmode: Optional[Any] = ...): ... From f706db837549716e2113e9f1ed47731157394cdc Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 11 Jan 2021 14:08:54 +0000 Subject: [PATCH 20/33] Fix in operator annotations (and corresponding imports) (#200) Co-authored-by: Ivan Levkivskyi --- sqlalchemy-stubs/sql/operators.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sqlalchemy-stubs/sql/operators.pyi b/sqlalchemy-stubs/sql/operators.pyi index e888de5..89a08e1 100644 --- a/sqlalchemy-stubs/sql/operators.pyi +++ b/sqlalchemy-stubs/sql/operators.pyi @@ -1,6 +1,6 @@ from typing import Any, Iterable, Optional, Text, Union -from .selectable import Select as Select -from .elements import BindParameter as BindParameter, UnaryExpression +from .selectable import Select, Alias +from .elements import BindParameter, UnaryExpression class Operators(object): def __and__(self, other): ... @@ -42,8 +42,8 @@ class ColumnOperators(Operators): def concat(self, other): ... def like(self, other: Text, escape: Optional[Any] = ...): ... def ilike(self, other: Text, escape: Optional[Any] = ...): ... - def in_(self, other: Union[Iterable[Any], BindParameter, Select]): ... - def notin_(self, other: Union[Iterable[Any], BindParameter, Select]): ... + def in_(self, other: Union[Iterable[Any], BindParameter, Select, Alias]): ... + def notin_(self, other: Union[Iterable[Any], BindParameter, Select, Alias]): ... def notlike(self, other, escape: Optional[Any] = ...): ... def notilike(self, other, escape: Optional[Any] = ...): ... def is_(self, other): ... From a82fa7a6093ae43a6144774cc134ee495911b7e3 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Tue, 12 Jan 2021 13:58:21 +0000 Subject: [PATCH 21/33] Bump version (#201) Co-authored-by: Ivan Levkivskyi --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index d46d697..50857f8 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ def find_stub_files(): setup(name='sqlalchemy-stubs', - version='0.3', + version='0.4', description=description, long_description=install_instructions, long_description_content_type='text/markdown', @@ -52,7 +52,7 @@ def find_stub_files(): url="https://github.com/dropbox/sqlalchemy-stubs", py_modules=['sqlmypy', 'sqltyping'], install_requires=[ - 'mypy>=0.720', + 'mypy>=0.790', 'typing-extensions>=3.7.4' ], packages=['sqlalchemy-stubs'], From 78ff38426bf44aa01055c0c93bc91f149afa7c93 Mon Sep 17 00:00:00 2001 From: "v.haritonskiy" Date: Thu, 11 Mar 2021 10:57:04 +0200 Subject: [PATCH 22/33] add methods to load --- sqlalchemy-stubs/orm/strategy_options.pyi | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sqlalchemy-stubs/orm/strategy_options.pyi b/sqlalchemy-stubs/orm/strategy_options.pyi index 5f05fff..e57c59d 100644 --- a/sqlalchemy-stubs/orm/strategy_options.pyi +++ b/sqlalchemy-stubs/orm/strategy_options.pyi @@ -16,6 +16,16 @@ class Load(Generative, MapperOption): def process_query_conditionally(self, query): ... def set_relationship_strategy(self, attr, strategy, propagate_to_loaders: bool = ...): ... def set_column_strategy(self, attrs, strategy, opts: Optional[Any] = ..., opts_only: bool = ...): ... + def load_only(self, *attrs): ... + def joinedload(self, attr): ... + def subqueryload(self, attr): ... + def immediateload(self, attr): ... + def noload(self, attr): ... + def raiseload(self, attr, sql_only: bool = ...): ... + def defaultload(self, attr): ... + def defer(self, key): ... + def undefer(self, key): ... + def undefer_group(self, name): ... class _UnboundLoad(Load): path: Any = ... From 8e1fb36c05c9f1de2f1211fea4707e68dcd8e83f Mon Sep 17 00:00:00 2001 From: "v.haritonskiy" Date: Thu, 25 Mar 2021 17:17:06 +0200 Subject: [PATCH 23/33] add pool lesser known members --- sqlalchemy-stubs/pool.pyi | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sqlalchemy-stubs/pool.pyi b/sqlalchemy-stubs/pool.pyi index 4269ebe..e462d7e 100644 --- a/sqlalchemy-stubs/pool.pyi +++ b/sqlalchemy-stubs/pool.pyi @@ -58,3 +58,15 @@ class AssertionPool(Pool): def status(self): ... def dispose(self): ... def recreate(self): ... + +class _ConnectionFairy: + def cursor(self): ... + def info(self): ... + def record_info(self): ... + def invalidate(self): ... + def detach(self): ... + def close(self): ... + +class _ConnectionRecord(object): + def info(self): ... + def checkout(self, pool): ... From 553b01697aa68641a479b1f243de4a064bf57732 Mon Sep 17 00:00:00 2001 From: "v.haritonskiy" Date: Tue, 28 Jun 2022 13:41:57 +0300 Subject: [PATCH 24/33] add row --- sqlalchemy-stubs/engine/row.pyi | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 sqlalchemy-stubs/engine/row.pyi diff --git a/sqlalchemy-stubs/engine/row.pyi b/sqlalchemy-stubs/engine/row.pyi new file mode 100644 index 0000000..c27588b --- /dev/null +++ b/sqlalchemy-stubs/engine/row.pyi @@ -0,0 +1,34 @@ +import sys + +from typing import Any, List, Mapping, Union, AbstractSet, Tuple +from ..sql.schema import Column + +if sys.version_info >= (3, 0): + _RowItems = AbstractSet[Tuple[str, Any]] +else: + _RowItems = List[Tuple[str, Any]] + +class BaseRow(Mapping[str, Any]): + def __init__(self, parent, row, processors, keymap) -> None: ... + def __reduce__(self): ... + def values(self): ... + def __iter__(self): ... + def __len__(self) -> int: ... + def __getitem__(self, key: Union[str, int, Column]) -> Any: ... + def __getattr__(self, name): ... + +class Row(BaseRow): + def __contains__(self, key): ... + __hash__: Any = ... + def __lt__(self, other): ... + def __le__(self, other): ... + def __ge__(self, other): ... + def __gt__(self, other): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + def has_key(self, key): ... + def items(self) -> _RowItems: ... + def keys(self): ... + def iterkeys(self): ... + def itervalues(self): ... + From bd6f78eedd543c615e39b6e642c5af8b462772c4 Mon Sep 17 00:00:00 2001 From: "v.haritonskiy" Date: Tue, 28 Jun 2022 13:42:17 +0300 Subject: [PATCH 25/33] add row --- sqlalchemy-stubs/engine/__init__.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sqlalchemy-stubs/engine/__init__.pyi b/sqlalchemy-stubs/engine/__init__.pyi index f4a89e0..ceb7e05 100644 --- a/sqlalchemy-stubs/engine/__init__.pyi +++ b/sqlalchemy-stubs/engine/__init__.pyi @@ -30,5 +30,7 @@ from .result import ( RowProxy as RowProxy, ) +from .row import Row + def create_engine(*args: Any, **kwargs: Any) -> Engine: ... def engine_from_config(configuration: Any, prefix: str = ..., **kwargs: Any) -> Engine: ... From 2f9e7e5dc990080ebee4a6036b5b382dbdb9c20d Mon Sep 17 00:00:00 2001 From: "v.haritonskiy" Date: Tue, 28 Jun 2022 16:27:15 +0300 Subject: [PATCH 26/33] add clauses --- sqlalchemy-stubs/orm/query.pyi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sqlalchemy-stubs/orm/query.pyi b/sqlalchemy-stubs/orm/query.pyi index bc89cdd..8d3f969 100644 --- a/sqlalchemy-stubs/orm/query.pyi +++ b/sqlalchemy-stubs/orm/query.pyi @@ -12,6 +12,10 @@ _Q = TypeVar('_Q', bound="Query") class Query(Generic[_T]): session: Session = ... + _limit_clause: Any = ... + _offset_clause: Any = ... + _group_by_clause: Any = ... + def __init__(self, entities, session: Optional[Session] = ...) -> None: ... # TODO: is "statement" always of type sqlalchemy.sql.selectable.Select ? From 63f59bddfe4ff68084ed34dc7492309bf8e2efee Mon Sep 17 00:00:00 2001 From: "v.haritonskiy" Date: Tue, 28 Jun 2022 16:28:56 +0300 Subject: [PATCH 27/33] add more --- sqlalchemy-stubs/engine/url.pyi | 1 + sqlalchemy-stubs/orm/query.pyi | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sqlalchemy-stubs/engine/url.pyi b/sqlalchemy-stubs/engine/url.pyi index 742e734..a4936d8 100644 --- a/sqlalchemy-stubs/engine/url.pyi +++ b/sqlalchemy-stubs/engine/url.pyi @@ -18,5 +18,6 @@ class URL(object): def get_driver_name(self): ... def get_dialect(self): ... def translate_connect_args(self, names: Any = ..., **kw): ... + def set(self, **kw): ... def make_url(name_or_url: Union[Text, bytes]) -> URL: ... diff --git a/sqlalchemy-stubs/orm/query.pyi b/sqlalchemy-stubs/orm/query.pyi index 8d3f969..8a277d2 100644 --- a/sqlalchemy-stubs/orm/query.pyi +++ b/sqlalchemy-stubs/orm/query.pyi @@ -17,7 +17,7 @@ class Query(Generic[_T]): _group_by_clause: Any = ... def __init__(self, entities, session: Optional[Session] = ...) -> None: ... - + def __next__(self): ... # TODO: is "statement" always of type sqlalchemy.sql.selectable.Select ? @property def statement(self): ... From 6e6b7a4eac6b90029d04d618d9b5c40223423243 Mon Sep 17 00:00:00 2001 From: "v.haritonskiy" Date: Wed, 29 Jun 2022 10:04:52 +0300 Subject: [PATCH 28/33] fix typo --- sqlalchemy-stubs/orm/query.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlalchemy-stubs/orm/query.pyi b/sqlalchemy-stubs/orm/query.pyi index 8a277d2..2393687 100644 --- a/sqlalchemy-stubs/orm/query.pyi +++ b/sqlalchemy-stubs/orm/query.pyi @@ -14,7 +14,7 @@ class Query(Generic[_T]): session: Session = ... _limit_clause: Any = ... _offset_clause: Any = ... - _group_by_clause: Any = ... + _group_by_clauses: Any = ... def __init__(self, entities, session: Optional[Session] = ...) -> None: ... def __next__(self): ... From db6fa0feaa2912d0f9e7fbe1e0bca91c62e9a700 Mon Sep 17 00:00:00 2001 From: "v.haritonskiy" Date: Wed, 29 Jun 2022 22:17:22 +0300 Subject: [PATCH 29/33] fix params --- sqlalchemy-stubs/engine/row.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlalchemy-stubs/engine/row.pyi b/sqlalchemy-stubs/engine/row.pyi index c27588b..a7acf85 100644 --- a/sqlalchemy-stubs/engine/row.pyi +++ b/sqlalchemy-stubs/engine/row.pyi @@ -9,7 +9,7 @@ else: _RowItems = List[Tuple[str, Any]] class BaseRow(Mapping[str, Any]): - def __init__(self, parent, row, processors, keymap) -> None: ... + def __init__(self, parent, row, processors, keymap, data) -> None: ... def __reduce__(self): ... def values(self): ... def __iter__(self): ... From 8e415dedf2f979e27957acfb8b96bb87dc56b01a Mon Sep 17 00:00:00 2001 From: "v.haritonskiy" Date: Thu, 30 Jun 2022 11:19:58 +0300 Subject: [PATCH 30/33] add version --- sqlalchemy-stubs/__init__.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sqlalchemy-stubs/__init__.pyi b/sqlalchemy-stubs/__init__.pyi index fbed294..5f22437 100644 --- a/sqlalchemy-stubs/__init__.pyi +++ b/sqlalchemy-stubs/__init__.pyi @@ -1,3 +1,4 @@ + from .sql import ( alias as alias, all_ as all_, @@ -140,3 +141,5 @@ from . import pool as pool from . import processors as processors from . import schema as schema from . import types as types + +__version__ = ... From 49417d1c1058e53cad9cef9f86ee0b21ca26ff1e Mon Sep 17 00:00:00 2001 From: "v.haritonskiy" Date: Sun, 3 Jul 2022 22:36:43 +0300 Subject: [PATCH 31/33] add compile stat --- sqlalchemy-stubs/orm/query.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/sqlalchemy-stubs/orm/query.pyi b/sqlalchemy-stubs/orm/query.pyi index 2393687..22c2f9b 100644 --- a/sqlalchemy-stubs/orm/query.pyi +++ b/sqlalchemy-stubs/orm/query.pyi @@ -28,6 +28,7 @@ class Query(Generic[_T]): @property def selectable(self): ... def __clause_element__(self): ... + def _compile_state(self):... def enable_eagerloads(self: _Q, value: bool) -> _Q: ... def with_labels(self: _Q) -> _Q: ... def enable_assertions(self: _Q, value: bool) -> _Q: ... From 499907028dc1f66f97b723448d86131beb71f02f Mon Sep 17 00:00:00 2001 From: "v.haritonskiy" Date: Thu, 4 May 2023 12:54:12 +0300 Subject: [PATCH 32/33] add declarative base --- sqlalchemy-stubs/orm/__init__.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlalchemy-stubs/orm/__init__.pyi b/sqlalchemy-stubs/orm/__init__.pyi index 32fd569..0cde35f 100644 --- a/sqlalchemy-stubs/orm/__init__.pyi +++ b/sqlalchemy-stubs/orm/__init__.pyi @@ -87,7 +87,7 @@ selectin_polymorphic: Any = ... def eagerload(*args, **kwargs): ... def eagerload_all(*args, **kwargs): ... - +def declarative_base(*args, **kwargs): ... contains_alias = AliasOption @@ -110,4 +110,4 @@ class MapperExtension: def before_update(self, mapper, connection, instance) -> Any: ... def after_update(self, mapper, connection, instance) -> Any: ... def before_delete(self, mapper, connection, instance) -> Any: ... - def after_delete(self, mapper, connection, instance) -> Any: ... \ No newline at end of file + def after_delete(self, mapper, connection, instance) -> Any: ... From a95ea2bd9105419bd223e742e95f2d604d34c60b Mon Sep 17 00:00:00 2001 From: "v.haritonskiy" Date: Mon, 8 May 2023 14:21:15 +0300 Subject: [PATCH 33/33] add missing stuff --- sqlalchemy-stubs/orm/__init__.pyi | 1 + sqlalchemy-stubs/orm/decl_base.py | 1 + sqlalchemy-stubs/sql/selectable.pyi | 1 + 3 files changed, 3 insertions(+) create mode 100644 sqlalchemy-stubs/orm/decl_base.py diff --git a/sqlalchemy-stubs/orm/__init__.pyi b/sqlalchemy-stubs/orm/__init__.pyi index 0cde35f..2c47f36 100644 --- a/sqlalchemy-stubs/orm/__init__.pyi +++ b/sqlalchemy-stubs/orm/__init__.pyi @@ -41,6 +41,7 @@ from .scoping import scoped_session as scoped_session from . import mapper as mapperlib from .query import AliasOption as AliasOption, Query as Query, Bundle as Bundle from .strategy_options import Load as Load +from ..ext.declarative import DeclarativeMeta def create_session(bind: Optional[Any] = ..., **kwargs): ... diff --git a/sqlalchemy-stubs/orm/decl_base.py b/sqlalchemy-stubs/orm/decl_base.py new file mode 100644 index 0000000..080f4f6 --- /dev/null +++ b/sqlalchemy-stubs/orm/decl_base.py @@ -0,0 +1 @@ +def _declarative_constructor(*args, **kwargs): ... diff --git a/sqlalchemy-stubs/sql/selectable.pyi b/sqlalchemy-stubs/sql/selectable.pyi index 74a5000..ce6024b 100644 --- a/sqlalchemy-stubs/sql/selectable.pyi +++ b/sqlalchemy-stubs/sql/selectable.pyi @@ -82,6 +82,7 @@ class Join(FromClause): def self_group(self, against: Optional[Any] = ...) -> FromGrouping: ... def get_children(self, **kwargs: Any) -> Tuple[FromClause, FromClause, ClauseElement]: ... def select(self, whereclause: Optional[Union[str, bool, Visitable]] = ..., **kwargs: Any) -> Select: ... + def where(self: _SE, whereclause: Union[str, bool, Visitable]) -> _SE: ... @property def bind(self) -> Optional[Union[Engine, Connection]]: ... # Return type of "alias" incompatible with supertype "FromClause"