From 492465a7025815d4304fb77f14c073a552a4f3b9 Mon Sep 17 00:00:00 2001 From: Hasier Date: Thu, 7 Apr 2022 11:30:40 +0100 Subject: [PATCH 1/3] SQLAlchemy improvements for generative methods --- .../sqlalchemy/ext/asyncio/engine.pyi | 2 +- .../SQLAlchemy/sqlalchemy/sql/selectable.pyi | 57 ++++++++++--------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/asyncio/engine.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/asyncio/engine.pyi index 5bb62f98b3fa..dbc88f378d93 100644 --- a/stubs/SQLAlchemy/sqlalchemy/ext/asyncio/engine.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/ext/asyncio/engine.pyi @@ -2,7 +2,7 @@ from typing import Any from .base import ProxyComparable, StartableContext -def create_async_engine(*arg, **kw): ... +def create_async_engine(*arg, **kw) -> AsyncEngine: ... class AsyncConnectable: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/sql/selectable.pyi b/stubs/SQLAlchemy/sqlalchemy/sql/selectable.pyi index abf7827e2131..bda33bdf23e7 100644 --- a/stubs/SQLAlchemy/sqlalchemy/sql/selectable.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/sql/selectable.pyi @@ -1,5 +1,6 @@ from typing import Any +from _typeshed import Self from .. import util from ..util import HasMemoized, memoized_property from . import roles, traversals, visitors @@ -37,14 +38,14 @@ class Selectable(ReturnsRows): def corresponding_column(self, column, require_embedded: bool = ...): ... class HasPrefixes: - def prefix_with(self, *expr, **kw) -> None: ... + def prefix_with(self: Self, *expr, **kw) -> Self: ... class HasSuffixes: - def suffix_with(self, *expr, **kw) -> None: ... + def suffix_with(self: Self, *expr, **kw) -> Self: ... class HasHints: def with_statement_hint(self, text, dialect_name: str = ...): ... - def with_hint(self, selectable, text, dialect_name: str = ...) -> None: ... + def with_hint(self: Self, selectable, text: str, dialect_name: str = ...) -> Self: ... class FromClause(roles.AnonymizedFromClauseRole, Selectable): __visit_name__: str @@ -190,9 +191,9 @@ class Values(Generative, FromClause): name: Any literal_binds: Any def __init__(self, *columns, **kw) -> None: ... - def alias(self, name, **kw) -> None: ... # type: ignore[override] - def lateral(self, name: Any | None = ...) -> None: ... - def data(self, values) -> None: ... + def alias(self: Self, name: Any | None, **kw) -> Self: ... # type: ignore[override] + def lateral(self: Self, name: Any | None = ...) -> Self: ... + def data(self: Self, values) -> Self: ... class SelectBase( roles.SelectStatementRole, @@ -250,17 +251,17 @@ class GenerativeSelect(DeprecatedSelectBaseGenerations, SelectBase): bind: Any | None = ..., ) -> None: ... def with_for_update( - self, nowait: bool = ..., read: bool = ..., of: Any | None = ..., skip_locked: bool = ..., key_share: bool = ... - ) -> None: ... + self: Self, nowait: bool = ..., read: bool = ..., of: Any | None = ..., skip_locked: bool = ..., key_share: bool = ... + ) -> Self: ... def get_label_style(self): ... def set_label_style(self, style): ... def apply_labels(self): ... - def limit(self, limit) -> None: ... - def fetch(self, count, with_ties: bool = ..., percent: bool = ...) -> None: ... - def offset(self, offset) -> None: ... - def slice(self, start, stop) -> None: ... - def order_by(self, *clauses) -> None: ... - def group_by(self, *clauses) -> None: ... + def limit(self: Self, limit: Any | None) -> Self: ... + def fetch(self: Self, count: Any | None, with_ties: bool = ..., percent: bool = ...) -> Self: ... + def offset(self: Self, offset: Any | None) -> Self: ... + def slice(self: Self, start: Any | None, stop: Any | None) -> Self: ... + def order_by(self: Self, *clauses) -> Self: ... + def group_by(self: Self, *clauses) -> Self: ... class CompoundSelectState(CompileState): ... @@ -338,9 +339,9 @@ class Select( @property def column_descriptions(self): ... def from_statement(self, statement): ... - def join(self, target, onclause: Any | None = ..., isouter: bool = ..., full: bool = ...) -> None: ... + def join(self, target, onclause: Any | None = ..., isouter: bool = ..., full: bool = ...) -> Self: ... def outerjoin_from(self, from_, target, onclause: Any | None = ..., full: bool = ...): ... - def join_from(self, from_, target, onclause: Any | None = ..., isouter: bool = ..., full: bool = ...) -> None: ... + def join_from(self, from_, target, onclause: Any | None = ..., isouter: bool = ..., full: bool = ...) -> Self: ... def outerjoin(self, target, onclause: Any | None = ..., full: bool = ...): ... def get_final_froms(self): ... @property @@ -351,18 +352,18 @@ class Select( def inner_columns(self): ... def is_derived_from(self, fromclause): ... def get_children(self, **kwargs): ... - def add_columns(self, *columns) -> None: ... + def add_columns(self, *columns) -> Self: ... def column(self, column): ... def reduce_columns(self, only_synonyms: bool = ...): ... - def with_only_columns(self, *columns, **kw) -> None: ... + def with_only_columns(self: Self, *columns, **kw) -> Self: ... @property def whereclause(self): ... - def where(self, *whereclause) -> None: ... - def having(self, having) -> None: ... - def distinct(self, *expr) -> None: ... - def select_from(self, *froms) -> None: ... - def correlate(self, *fromclauses) -> None: ... - def correlate_except(self, *fromclauses) -> None: ... + def where(self: Self, *whereclause) -> Self: ... + def having(self: Self, having) -> Self: ... + def distinct(self: Self, *expr) -> Self: ... + def select_from(self: Self, *froms) -> Self: ... + def correlate(self: Self, *fromclauses) -> Self: ... + def correlate_except(self: Self, *fromclauses) -> Self: ... @HasMemoized.memoized_attribute def selected_columns(self): ... def self_group(self, against: Any | None = ...): ... @@ -386,10 +387,10 @@ class ScalarSelect(roles.InElementRole, Generative, Grouping): def columns(self) -> None: ... @property def c(self): ... - def where(self, crit) -> None: ... + def where(self: Self, crit) -> Self: ... def self_group(self, **kwargs): ... - def correlate(self, *fromclauses) -> None: ... - def correlate_except(self, *fromclauses) -> None: ... + def correlate(self: Self, *fromclauses) -> Self: ... + def correlate_except(self: Self, *fromclauses) -> Self: ... class Exists(UnaryExpression): inherit_cache: bool @@ -410,7 +411,7 @@ class TextualSelect(SelectBase): def __init__(self, text, columns, positional: bool = ...) -> None: ... @HasMemoized.memoized_attribute def selected_columns(self): ... - def bindparams(self, *binds, **bind_as_values) -> None: ... + def bindparams(self: Self, *binds, **bind_as_values) -> Self: ... TextAsFrom = TextualSelect From d7a7abfaf900d3a4f94ff07599c59b48306c6911 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 7 Apr 2022 10:36:19 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/SQLAlchemy/sqlalchemy/sql/selectable.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/SQLAlchemy/sqlalchemy/sql/selectable.pyi b/stubs/SQLAlchemy/sqlalchemy/sql/selectable.pyi index bda33bdf23e7..02bf8ef03653 100644 --- a/stubs/SQLAlchemy/sqlalchemy/sql/selectable.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/sql/selectable.pyi @@ -1,6 +1,6 @@ +from _typeshed import Self from typing import Any -from _typeshed import Self from .. import util from ..util import HasMemoized, memoized_property from . import roles, traversals, visitors From 218ecec15777c64c4de736c0e414497778d87f35 Mon Sep 17 00:00:00 2001 From: Hasier Date: Thu, 7 Apr 2022 11:40:36 +0100 Subject: [PATCH 3/3] Fix missing Self references --- stubs/SQLAlchemy/sqlalchemy/sql/selectable.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stubs/SQLAlchemy/sqlalchemy/sql/selectable.pyi b/stubs/SQLAlchemy/sqlalchemy/sql/selectable.pyi index 02bf8ef03653..892c53230aea 100644 --- a/stubs/SQLAlchemy/sqlalchemy/sql/selectable.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/sql/selectable.pyi @@ -339,9 +339,9 @@ class Select( @property def column_descriptions(self): ... def from_statement(self, statement): ... - def join(self, target, onclause: Any | None = ..., isouter: bool = ..., full: bool = ...) -> Self: ... + def join(self: Self, target, onclause: Any | None = ..., isouter: bool = ..., full: bool = ...) -> Self: ... def outerjoin_from(self, from_, target, onclause: Any | None = ..., full: bool = ...): ... - def join_from(self, from_, target, onclause: Any | None = ..., isouter: bool = ..., full: bool = ...) -> Self: ... + def join_from(self: Self, from_, target, onclause: Any | None = ..., isouter: bool = ..., full: bool = ...) -> Self: ... def outerjoin(self, target, onclause: Any | None = ..., full: bool = ...): ... def get_final_froms(self): ... @property @@ -352,7 +352,7 @@ class Select( def inner_columns(self): ... def is_derived_from(self, fromclause): ... def get_children(self, **kwargs): ... - def add_columns(self, *columns) -> Self: ... + def add_columns(self: Self, *columns) -> Self: ... def column(self, column): ... def reduce_columns(self, only_synonyms: bool = ...): ... def with_only_columns(self: Self, *columns, **kw) -> Self: ...