From 2a552fa78e626387f089979f6d4459f552812f22 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 11 Jan 2023 00:35:48 -0500 Subject: [PATCH 1/5] Use mypy type in SQLAlchemy/ext/mypy --- stubs/SQLAlchemy/METADATA.toml | 1 + .../SQLAlchemy/sqlalchemy/ext/mypy/apply.pyi | 27 ++++----- .../sqlalchemy/ext/mypy/decl_class.pyi | 7 +-- .../SQLAlchemy/sqlalchemy/ext/mypy/infer.pyi | 32 +++++------ .../SQLAlchemy/sqlalchemy/ext/mypy/names.pyi | 24 +++----- .../SQLAlchemy/sqlalchemy/ext/mypy/plugin.pyi | 27 ++++----- stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi | 57 ++++++++----------- 7 files changed, 70 insertions(+), 105 deletions(-) diff --git a/stubs/SQLAlchemy/METADATA.toml b/stubs/SQLAlchemy/METADATA.toml index f58115dbfea3..cf918c3379ce 100644 --- a/stubs/SQLAlchemy/METADATA.toml +++ b/stubs/SQLAlchemy/METADATA.toml @@ -1,4 +1,5 @@ version = "1.4.46" +requires = ["mypy"] extra_description = """\ The `sqlalchemy-stubs` package is an alternative to this package and also \ includes a mypy plugin for more precise types.\ diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/apply.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/apply.pyi index 651f37c031c8..7ada820e84df 100644 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/apply.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/apply.pyi @@ -1,27 +1,22 @@ -from typing import Any -from typing_extensions import TypeAlias +from mypy.nodes import AssignmentStmt, NameExpr, StrExpr +from mypy.plugin import SemanticAnalyzerPluginInterface +from mypy.types import ProperType from . import util -_AssignmentStmt: TypeAlias = Any # mypy.nodes.AssignmentStmt -_NameExpr: TypeAlias = Any # mypy.nodes.NameExpr -_StrExpr: TypeAlias = Any # mypy.nodes.StrExpr -_SemanticAnalyzerPluginInterface: TypeAlias = Any # mypy.plugin.SemanticAnalyzerPluginInterface -_ProperType: TypeAlias = Any # mypy.types.ProperType - def apply_mypy_mapped_attr( - cls, api: _SemanticAnalyzerPluginInterface, item: _NameExpr | _StrExpr, attributes: list[util.SQLAlchemyAttribute] + cls, api: SemanticAnalyzerPluginInterface, item: NameExpr | StrExpr, attributes: list[util.SQLAlchemyAttribute] ) -> None: ... def re_apply_declarative_assignments( - cls, api: _SemanticAnalyzerPluginInterface, attributes: list[util.SQLAlchemyAttribute] + cls, api: SemanticAnalyzerPluginInterface, attributes: list[util.SQLAlchemyAttribute] ) -> None: ... def apply_type_to_mapped_statement( - api: _SemanticAnalyzerPluginInterface, - stmt: _AssignmentStmt, - lvalue: _NameExpr, - left_hand_explicit_type: _ProperType | None, - python_type_for_type: _ProperType | None, + api: SemanticAnalyzerPluginInterface, + stmt: AssignmentStmt, + lvalue: NameExpr, + left_hand_explicit_type: ProperType | None, + python_type_for_type: ProperType | None, ) -> None: ... def add_additional_orm_attributes( - cls, api: _SemanticAnalyzerPluginInterface, attributes: list[util.SQLAlchemyAttribute] + cls, api: SemanticAnalyzerPluginInterface, attributes: list[util.SQLAlchemyAttribute] ) -> None: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/decl_class.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/decl_class.pyi index 9b68ea889205..323d84f1b93c 100644 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/decl_class.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/decl_class.pyi @@ -1,10 +1,7 @@ -from typing import Any -from typing_extensions import TypeAlias +from mypy.plugin import SemanticAnalyzerPluginInterface from . import util -_SemanticAnalyzerPluginInterface: TypeAlias = Any # mypy.plugin.SemanticAnalyzerPluginInterface - def scan_declarative_assignments_and_apply_types( - cls, api: _SemanticAnalyzerPluginInterface, is_mixin_scan: bool = ... + cls, api: SemanticAnalyzerPluginInterface, is_mixin_scan: bool = ... ) -> list[util.SQLAlchemyAttribute] | None: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/infer.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/infer.pyi index 0ffb05b70360..7dfb7ec62165 100644 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/infer.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/infer.pyi @@ -1,25 +1,19 @@ from collections.abc import Sequence -from typing import Any -from typing_extensions import TypeAlias -_AssignmentStmt: TypeAlias = Any # mypy.nodes.AssignmentStmt -_Expression: TypeAlias = Any # mypy.nodes.Expression -_RefExpr: TypeAlias = Any # mypy.nodes.RefExpr -_TypeInfo: TypeAlias = Any # mypy.nodes.TypeInfo -_Var: TypeAlias = Any # mypy.nodes.Var -_SemanticAnalyzerPluginInterface: TypeAlias = Any # mypy.plugin.SemanticAnalyzerPluginInterface -_ProperType: TypeAlias = Any # mypy.types.ProperType +from mypy.nodes import AssignmentStmt, Expression, RefExpr, TypeInfo, Var +from mypy.plugin import SemanticAnalyzerPluginInterface +from mypy.types import ProperType def infer_type_from_right_hand_nameexpr( - api: _SemanticAnalyzerPluginInterface, - stmt: _AssignmentStmt, - node: _Var, - left_hand_explicit_type: _ProperType | None, - infer_from_right_side: _RefExpr, -) -> _ProperType | None: ... + api: SemanticAnalyzerPluginInterface, + stmt: AssignmentStmt, + node: Var, + left_hand_explicit_type: ProperType | None, + infer_from_right_side: RefExpr, +) -> ProperType | None: ... def infer_type_from_left_hand_type_only( - api: _SemanticAnalyzerPluginInterface, node: _Var, left_hand_explicit_type: _ProperType | None -) -> _ProperType | None: ... + api: SemanticAnalyzerPluginInterface, node: Var, left_hand_explicit_type: ProperType | None +) -> ProperType | None: ... def extract_python_type_from_typeengine( - api: _SemanticAnalyzerPluginInterface, node: _TypeInfo, type_args: Sequence[_Expression] -) -> _ProperType: ... + api: SemanticAnalyzerPluginInterface, node: TypeInfo, type_args: Sequence[Expression] +) -> ProperType: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi index ab998e2bcd4d..7906d4e5635b 100644 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi @@ -1,17 +1,9 @@ -from typing import Any -from typing_extensions import TypeAlias +from mypy.nodes import ClassDef, Expression, MemberExpr, NameExpr, SymbolNode, TypeInfo +from mypy.plugin import SemanticAnalyzerPluginInterface +from mypy.types import UnboundType from ...util import symbol -_ClassDef: TypeAlias = Any # mypy.nodes.ClassDef -_Expression: TypeAlias = Any # mypy.nodes.Expression -_MemberExpr: TypeAlias = Any # mypy.nodes.MemberExpr -_NameExpr: TypeAlias = Any # mypy.nodes.NameExpr -_SymbolNode: TypeAlias = Any # mypy.nodes.SymbolNode -_TypeInfo: TypeAlias = Any # mypy.nodes.TypeInfo -_SemanticAnalyzerPluginInterface: TypeAlias = Any # mypy.plugin.SemanticAnalyzerPluginInterface -_UnboundType: TypeAlias = Any # mypy.types.UnboundType - COLUMN: symbol RELATIONSHIP: symbol REGISTRY: symbol @@ -30,9 +22,9 @@ AS_DECLARATIVE_BASE: symbol DECLARATIVE_MIXIN: symbol QUERY_EXPRESSION: symbol -def has_base_type_id(info: _TypeInfo, type_id: int) -> bool: ... -def mro_has_id(mro: list[_TypeInfo], type_id: int) -> bool: ... -def type_id_for_unbound_type(type_: _UnboundType, cls: _ClassDef, api: _SemanticAnalyzerPluginInterface) -> int | None: ... -def type_id_for_callee(callee: _Expression) -> int | None: ... -def type_id_for_named_node(node: _NameExpr | _MemberExpr | _SymbolNode) -> int | None: ... +def has_base_type_id(info: TypeInfo, type_id: int) -> bool: ... +def mro_has_id(mro: list[TypeInfo], type_id: int) -> bool: ... +def type_id_for_unbound_type(type_: UnboundType, cls: ClassDef, api: SemanticAnalyzerPluginInterface) -> int | None: ... +def type_id_for_callee(callee: Expression) -> int | None: ... +def type_id_for_named_node(node: NameExpr | MemberExpr | SymbolNode) -> int | None: ... def type_id_for_fullname(fullname: str) -> int | None: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/plugin.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/plugin.pyi index c9e943a1e02d..39f6f265dbac 100644 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/plugin.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/plugin.pyi @@ -1,21 +1,16 @@ from collections.abc import Callable -from typing import Any -from typing_extensions import TypeAlias -_MypyFile: TypeAlias = Any # mypy.nodes.MypyFile -_AttributeContext: TypeAlias = Any # mypy.plugin.AttributeContext -_ClassDefContext: TypeAlias = Any # mypy.plugin.ClassDefContext -_DynamicClassDefContext: TypeAlias = Any # mypy.plugin.DynamicClassDefContext -_Plugin: TypeAlias = Any # mypy.plugin.Plugin -_Type: TypeAlias = Any # mypy.types.Type +from mypy.nodes import MypyFile +from mypy.plugin import AttributeContext, ClassDefContext, DynamicClassDefContext, Plugin +from mypy.types import Type -class SQLAlchemyPlugin(_Plugin): - def get_dynamic_class_hook(self, fullname: str) -> Callable[[_DynamicClassDefContext], None] | None: ... - def get_customize_class_mro_hook(self, fullname: str) -> Callable[[_ClassDefContext], None] | None: ... - def get_class_decorator_hook(self, fullname: str) -> Callable[[_ClassDefContext], None] | None: ... - def get_metaclass_hook(self, fullname: str) -> Callable[[_ClassDefContext], None] | None: ... - def get_base_class_hook(self, fullname: str) -> Callable[[_ClassDefContext], None] | None: ... - def get_attribute_hook(self, fullname: str) -> Callable[[_AttributeContext], _Type] | None: ... - def get_additional_deps(self, file: _MypyFile) -> list[tuple[int, str, int]]: ... +class SQLAlchemyPlugin(Plugin): + def get_dynamic_class_hook(self, fullname: str) -> Callable[[DynamicClassDefContext], None] | None: ... + def get_customize_class_mro_hook(self, fullname: str) -> Callable[[ClassDefContext], None] | None: ... + def get_class_decorator_hook(self, fullname: str) -> Callable[[ClassDefContext], None] | None: ... + def get_metaclass_hook(self, fullname: str) -> Callable[[ClassDefContext], None] | None: ... + def get_base_class_hook(self, fullname: str) -> Callable[[ClassDefContext], None] | None: ... + def get_attribute_hook(self, fullname: str) -> Callable[[AttributeContext], Type] | None: ... + def get_additional_deps(self, file: MypyFile) -> list[tuple[int, str, int]]: ... def plugin(version: str) -> type[SQLAlchemyPlugin]: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi index 43edf16d8862..9bc11b403ec4 100644 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi @@ -1,20 +1,11 @@ from collections.abc import Iterable, Iterator from typing import Any, TypeVar, overload -from typing_extensions import TypeAlias -_CallExpr: TypeAlias = Any # mypy.nodes._CallExpr -_Context: TypeAlias = Any # mypy.nodes._Context -_Expression: TypeAlias = Any # mypy.nodes._Expression -_JsonDict: TypeAlias = Any # mypy.nodes._JsonDict -_NameExpr: TypeAlias = Any # mypy.nodes._NameExpr -_Statement: TypeAlias = Any # mypy.nodes._Statement -_TypeInfo: TypeAlias = Any # mypy.nodes._TypeInfo -_ClassDefContext: TypeAlias = Any # mypy.plugin._ClassDefContext -_DynamicClassDefContext: TypeAlias = Any # mypy.plugin._DynamicClassDefContext -_SemanticAnalyzerPluginInterface: TypeAlias = Any # mypy.plugin._SemanticAnalyzerPluginInterface -_Type: TypeAlias = Any # mypy.types._Type +from mypy.nodes import CallExpr, Context, Expression, JsonDict, NameExpr, Statement, TypeInfo +from mypy.plugin import ClassDefContext, DynamicClassDefContext, SemanticAnalyzerPluginInterface +from mypy.types import Type -_TArgType = TypeVar("_TArgType", bound=_CallExpr | _NameExpr) +_TArgType = TypeVar("_TArgType", bound=CallExpr | NameExpr) class SQLAlchemyAttribute: name: Any @@ -22,28 +13,28 @@ class SQLAlchemyAttribute: column: Any type: Any info: Any - def __init__(self, name: str, line: int, column: int, typ: _Type | None, info: _TypeInfo) -> None: ... - def serialize(self) -> _JsonDict: ... - def expand_typevar_from_subtype(self, sub_type: _TypeInfo) -> None: ... + def __init__(self, name: str, line: int, column: int, typ: Type | None, info: TypeInfo) -> None: ... + def serialize(self) -> JsonDict: ... + def expandtypevar_from_subtype(self, subtype: TypeInfo) -> None: ... @classmethod - def deserialize(cls, info: _TypeInfo, data: _JsonDict, api: _SemanticAnalyzerPluginInterface) -> SQLAlchemyAttribute: ... + def deserialize(cls, info: TypeInfo, data: JsonDict, api: SemanticAnalyzerPluginInterface) -> SQLAlchemyAttribute: ... def name_is_dunder(name): ... -def establish_as_sqlalchemy(info: _TypeInfo) -> None: ... -def set_is_base(info: _TypeInfo) -> None: ... -def get_is_base(info: _TypeInfo) -> bool: ... -def has_declarative_base(info: _TypeInfo) -> bool: ... -def set_has_table(info: _TypeInfo) -> None: ... -def get_has_table(info: _TypeInfo) -> bool: ... -def get_mapped_attributes(info: _TypeInfo, api: _SemanticAnalyzerPluginInterface) -> list[SQLAlchemyAttribute] | None: ... -def set_mapped_attributes(info: _TypeInfo, attributes: list[SQLAlchemyAttribute]) -> None: ... -def fail(api: _SemanticAnalyzerPluginInterface, msg: str, ctx: _Context) -> None: ... -def add_global(ctx: _ClassDefContext | _DynamicClassDefContext, module: str, symbol_name: str, asname: str) -> None: ... +def establish_as_sqlalchemy(info: TypeInfo) -> None: ... +def set_is_base(info: TypeInfo) -> None: ... +def get_is_base(info: TypeInfo) -> bool: ... +def has_declarative_base(info: TypeInfo) -> bool: ... +def set_has_table(info: TypeInfo) -> None: ... +def get_has_table(info: TypeInfo) -> bool: ... +def get_mapped_attributes(info: TypeInfo, api: SemanticAnalyzerPluginInterface) -> list[SQLAlchemyAttribute] | None: ... +def set_mapped_attributes(info: TypeInfo, attributes: list[SQLAlchemyAttribute]) -> None: ... +def fail(api: SemanticAnalyzerPluginInterface, msg: str, ctx: Context) -> None: ... +def add_global(ctx: ClassDefContext | DynamicClassDefContext, module: str, symbol_name: str, asname: str) -> None: ... @overload -def get_callexpr_kwarg(callexpr: _CallExpr, name: str, *, expr_types: None = ...) -> _CallExpr | _NameExpr | None: ... +def getcallexpr_kwarg(callexpr: CallExpr, name: str, *, exprtypes: None = ...) -> CallExpr | NameExpr | None: ... @overload -def get_callexpr_kwarg(callexpr: _CallExpr, name: str, *, expr_types: tuple[type[_TArgType], ...]) -> _TArgType | None: ... -def flatten_typechecking(stmts: Iterable[_Statement]) -> Iterator[_Statement]: ... -def unbound_to_instance(api: _SemanticAnalyzerPluginInterface, typ: _Type) -> _Type: ... -def info_for_cls(cls, api: _SemanticAnalyzerPluginInterface) -> _TypeInfo | None: ... -def expr_to_mapped_constructor(expr: _Expression) -> _CallExpr: ... +def getcallexpr_kwarg(callexpr: CallExpr, name: str, *, exprtypes: tuple[type[_TArgType], ...]) -> _TArgType | None: ... +def flattentypechecking(stmts: Iterable[Statement]) -> Iterator[Statement]: ... +def unbound_to_instance(api: SemanticAnalyzerPluginInterface, typ: Type) -> Type: ... +def info_for_cls(cls, api: SemanticAnalyzerPluginInterface) -> TypeInfo | None: ... +def expr_to_mapped_constructor(expr: Expression) -> CallExpr: ... From 2e0b9e52c5d1d44c3f40194bbb5c704ec12f3348 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 11 Jan 2023 04:49:51 -0500 Subject: [PATCH 2/5] Don't depend on mypy --- stubs/SQLAlchemy/METADATA.toml | 1 - stubs/SQLAlchemy/sqlalchemy/ext/mypy/apply.pyi | 7 ++++--- .../SQLAlchemy/sqlalchemy/ext/mypy/decl_class.pyi | 3 ++- stubs/SQLAlchemy/sqlalchemy/ext/mypy/infer.pyi | 7 ++++--- stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi | 7 ++++--- stubs/SQLAlchemy/sqlalchemy/ext/mypy/plugin.pyi | 7 ++++--- stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi | 15 ++++++++------- 7 files changed, 26 insertions(+), 21 deletions(-) diff --git a/stubs/SQLAlchemy/METADATA.toml b/stubs/SQLAlchemy/METADATA.toml index cf918c3379ce..f58115dbfea3 100644 --- a/stubs/SQLAlchemy/METADATA.toml +++ b/stubs/SQLAlchemy/METADATA.toml @@ -1,5 +1,4 @@ version = "1.4.46" -requires = ["mypy"] extra_description = """\ The `sqlalchemy-stubs` package is an alternative to this package and also \ includes a mypy plugin for more precise types.\ diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/apply.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/apply.pyi index 7ada820e84df..b809bb13a4f6 100644 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/apply.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/apply.pyi @@ -1,6 +1,7 @@ -from mypy.nodes import AssignmentStmt, NameExpr, StrExpr -from mypy.plugin import SemanticAnalyzerPluginInterface -from mypy.types import ProperType +# mypy_test can't find mypy import +from mypy.nodes import AssignmentStmt, NameExpr, StrExpr # type: ignore[import] +from mypy.plugin import SemanticAnalyzerPluginInterface # type: ignore[import] +from mypy.types import ProperType # type: ignore[import] from . import util diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/decl_class.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/decl_class.pyi index 323d84f1b93c..dbf0975e9e7f 100644 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/decl_class.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/decl_class.pyi @@ -1,4 +1,5 @@ -from mypy.plugin import SemanticAnalyzerPluginInterface +# mypy_test can't find mypy import +from mypy.plugin import SemanticAnalyzerPluginInterface # type: ignore[import] from . import util diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/infer.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/infer.pyi index 7dfb7ec62165..77bee57bc01a 100644 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/infer.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/infer.pyi @@ -1,8 +1,9 @@ from collections.abc import Sequence -from mypy.nodes import AssignmentStmt, Expression, RefExpr, TypeInfo, Var -from mypy.plugin import SemanticAnalyzerPluginInterface -from mypy.types import ProperType +# mypy_test can't find mypy import +from mypy.nodes import AssignmentStmt, Expression, RefExpr, TypeInfo, Var # type: ignore[import] +from mypy.plugin import SemanticAnalyzerPluginInterface # type: ignore[import] +from mypy.types import ProperType # type: ignore[import] def infer_type_from_right_hand_nameexpr( api: SemanticAnalyzerPluginInterface, diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi index 7906d4e5635b..80a367e44051 100644 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi @@ -1,6 +1,7 @@ -from mypy.nodes import ClassDef, Expression, MemberExpr, NameExpr, SymbolNode, TypeInfo -from mypy.plugin import SemanticAnalyzerPluginInterface -from mypy.types import UnboundType +# mypy_test can't find mypy import +from mypy.nodes import ClassDef, Expression, MemberExpr, NameExpr, SymbolNode, TypeInfo # type: ignore[import] +from mypy.plugin import SemanticAnalyzerPluginInterface # type: ignore[import] +from mypy.types import UnboundType # type: ignore[import] from ...util import symbol diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/plugin.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/plugin.pyi index 39f6f265dbac..af760ab87900 100644 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/plugin.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/plugin.pyi @@ -1,8 +1,9 @@ from collections.abc import Callable -from mypy.nodes import MypyFile -from mypy.plugin import AttributeContext, ClassDefContext, DynamicClassDefContext, Plugin -from mypy.types import Type +# mypy_test can't find mypy import +from mypy.nodes import MypyFile # type: ignore[import] +from mypy.plugin import AttributeContext, ClassDefContext, DynamicClassDefContext, Plugin # type: ignore[import] +from mypy.types import Type # type: ignore[import] class SQLAlchemyPlugin(Plugin): def get_dynamic_class_hook(self, fullname: str) -> Callable[[DynamicClassDefContext], None] | None: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi index 9bc11b403ec4..445c49c877e4 100644 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi @@ -1,9 +1,10 @@ from collections.abc import Iterable, Iterator from typing import Any, TypeVar, overload -from mypy.nodes import CallExpr, Context, Expression, JsonDict, NameExpr, Statement, TypeInfo -from mypy.plugin import ClassDefContext, DynamicClassDefContext, SemanticAnalyzerPluginInterface -from mypy.types import Type +# mypy_test can't find mypy import +from mypy.nodes import CallExpr, Context, Expression, JsonDict, NameExpr, Statement, TypeInfo # type: ignore[import] +from mypy.plugin import ClassDefContext, DynamicClassDefContext, SemanticAnalyzerPluginInterface # type: ignore[import] +from mypy.types import Type # type: ignore[import] _TArgType = TypeVar("_TArgType", bound=CallExpr | NameExpr) @@ -15,7 +16,7 @@ class SQLAlchemyAttribute: info: Any def __init__(self, name: str, line: int, column: int, typ: Type | None, info: TypeInfo) -> None: ... def serialize(self) -> JsonDict: ... - def expandtypevar_from_subtype(self, subtype: TypeInfo) -> None: ... + def expand_typevar_from_subtype(self, sub_type: TypeInfo) -> None: ... @classmethod def deserialize(cls, info: TypeInfo, data: JsonDict, api: SemanticAnalyzerPluginInterface) -> SQLAlchemyAttribute: ... @@ -31,10 +32,10 @@ def set_mapped_attributes(info: TypeInfo, attributes: list[SQLAlchemyAttribute]) def fail(api: SemanticAnalyzerPluginInterface, msg: str, ctx: Context) -> None: ... def add_global(ctx: ClassDefContext | DynamicClassDefContext, module: str, symbol_name: str, asname: str) -> None: ... @overload -def getcallexpr_kwarg(callexpr: CallExpr, name: str, *, exprtypes: None = ...) -> CallExpr | NameExpr | None: ... +def get_callexpr_kwarg(callexpr: CallExpr, name: str, *, expr_types: None = ...) -> CallExpr | NameExpr | None: ... @overload -def getcallexpr_kwarg(callexpr: CallExpr, name: str, *, exprtypes: tuple[type[_TArgType], ...]) -> _TArgType | None: ... -def flattentypechecking(stmts: Iterable[Statement]) -> Iterator[Statement]: ... +def get_callexpr_kwarg(callexpr: CallExpr, name: str, *, expr_types: tuple[type[_TArgType], ...]) -> _TArgType | None: ... +def flatten_typechecking(stmts: Iterable[Statement]) -> Iterator[Statement]: ... def unbound_to_instance(api: SemanticAnalyzerPluginInterface, typ: Type) -> Type: ... def info_for_cls(cls, api: SemanticAnalyzerPluginInterface) -> TypeInfo | None: ... def expr_to_mapped_constructor(expr: Expression) -> CallExpr: ... From a02cfe17949f3539ab6132df10597faa0ca17e32 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 11 Jan 2023 05:00:26 -0500 Subject: [PATCH 3/5] Add stubs/SQLAlchemy/sqlalchemy/ext/mypy to pytype exclude --- tests/pytype_exclude_list.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/pytype_exclude_list.txt b/tests/pytype_exclude_list.txt index 5a857e22c161..b3df64f8cae3 100644 --- a/tests/pytype_exclude_list.txt +++ b/tests/pytype_exclude_list.txt @@ -109,3 +109,11 @@ stubs/SQLAlchemy/sqlalchemy/sql/selectable.pyi stubs/Flask-SQLAlchemy/flask_sqlalchemy/__init__.pyi stubs/Flask-SQLAlchemy/flask_sqlalchemy/model.pyi stubs/Flask-SQLAlchemy/flask_sqlalchemy/utils.pyi + +# mypy extensions +stubs/SQLAlchemy/sqlalchemy/ext/mypy/apply.pyi +stubs/SQLAlchemy/sqlalchemy/ext/mypy/decl_class.pyi +stubs/SQLAlchemy/sqlalchemy/ext/mypy/infer.pyi +stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi +stubs/SQLAlchemy/sqlalchemy/ext/mypy/plugin.pyi +stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi From e4e2b29040301bd3ca51dfe782905b9f4b3432d6 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 11 Jan 2023 05:12:48 -0500 Subject: [PATCH 4/5] Remove _AsyncIoGreenlet --- stubs/SQLAlchemy/sqlalchemy/util/_concurrency_py3k.pyi | 9 --------- 1 file changed, 9 deletions(-) diff --git a/stubs/SQLAlchemy/sqlalchemy/util/_concurrency_py3k.pyi b/stubs/SQLAlchemy/sqlalchemy/util/_concurrency_py3k.pyi index 702ef9ea1fa6..f2fea9f5dcc0 100644 --- a/stubs/SQLAlchemy/sqlalchemy/util/_concurrency_py3k.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/util/_concurrency_py3k.pyi @@ -1,19 +1,10 @@ import asyncio as asyncio from collections.abc import Callable, Coroutine from typing import Any -from typing_extensions import TypeAlias from .langhelpers import memoized_property -_Greenlet: TypeAlias = Any # actually greenlet.greenlet - def is_exit_exception(e): ... - -class _AsyncIoGreenlet(_Greenlet): - driver: Any - gr_context: Any - def __init__(self, fn, driver) -> None: ... - def await_only(awaitable: Coroutine[Any, Any, Any]) -> Any: ... def await_fallback(awaitable: Coroutine[Any, Any, Any]) -> Any: ... async def greenlet_spawn(fn: Callable[..., Any], *args, _require_await: bool = ..., **kwargs) -> Any: ... From 07ad378e64546f621c6e75d48a6b420e50c00b18 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 11 Jan 2023 06:08:15 -0500 Subject: [PATCH 5/5] Removed stubs/SQLAlchemy/sqlalchemy/ext/mypy --- .../sqlalchemy/ext/mypy/__init__.pyi | 0 .../SQLAlchemy/sqlalchemy/ext/mypy/apply.pyi | 23 ----------- .../sqlalchemy/ext/mypy/decl_class.pyi | 8 ---- .../SQLAlchemy/sqlalchemy/ext/mypy/infer.pyi | 20 --------- .../SQLAlchemy/sqlalchemy/ext/mypy/names.pyi | 31 -------------- .../SQLAlchemy/sqlalchemy/ext/mypy/plugin.pyi | 17 -------- stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi | 41 ------------------- tests/pytype_exclude_list.txt | 8 ---- 8 files changed, 148 deletions(-) delete mode 100644 stubs/SQLAlchemy/sqlalchemy/ext/mypy/__init__.pyi delete mode 100644 stubs/SQLAlchemy/sqlalchemy/ext/mypy/apply.pyi delete mode 100644 stubs/SQLAlchemy/sqlalchemy/ext/mypy/decl_class.pyi delete mode 100644 stubs/SQLAlchemy/sqlalchemy/ext/mypy/infer.pyi delete mode 100644 stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi delete mode 100644 stubs/SQLAlchemy/sqlalchemy/ext/mypy/plugin.pyi delete mode 100644 stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/__init__.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/__init__.pyi deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/apply.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/apply.pyi deleted file mode 100644 index b809bb13a4f6..000000000000 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/apply.pyi +++ /dev/null @@ -1,23 +0,0 @@ -# mypy_test can't find mypy import -from mypy.nodes import AssignmentStmt, NameExpr, StrExpr # type: ignore[import] -from mypy.plugin import SemanticAnalyzerPluginInterface # type: ignore[import] -from mypy.types import ProperType # type: ignore[import] - -from . import util - -def apply_mypy_mapped_attr( - cls, api: SemanticAnalyzerPluginInterface, item: NameExpr | StrExpr, attributes: list[util.SQLAlchemyAttribute] -) -> None: ... -def re_apply_declarative_assignments( - cls, api: SemanticAnalyzerPluginInterface, attributes: list[util.SQLAlchemyAttribute] -) -> None: ... -def apply_type_to_mapped_statement( - api: SemanticAnalyzerPluginInterface, - stmt: AssignmentStmt, - lvalue: NameExpr, - left_hand_explicit_type: ProperType | None, - python_type_for_type: ProperType | None, -) -> None: ... -def add_additional_orm_attributes( - cls, api: SemanticAnalyzerPluginInterface, attributes: list[util.SQLAlchemyAttribute] -) -> None: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/decl_class.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/decl_class.pyi deleted file mode 100644 index dbf0975e9e7f..000000000000 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/decl_class.pyi +++ /dev/null @@ -1,8 +0,0 @@ -# mypy_test can't find mypy import -from mypy.plugin import SemanticAnalyzerPluginInterface # type: ignore[import] - -from . import util - -def scan_declarative_assignments_and_apply_types( - cls, api: SemanticAnalyzerPluginInterface, is_mixin_scan: bool = ... -) -> list[util.SQLAlchemyAttribute] | None: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/infer.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/infer.pyi deleted file mode 100644 index 77bee57bc01a..000000000000 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/infer.pyi +++ /dev/null @@ -1,20 +0,0 @@ -from collections.abc import Sequence - -# mypy_test can't find mypy import -from mypy.nodes import AssignmentStmt, Expression, RefExpr, TypeInfo, Var # type: ignore[import] -from mypy.plugin import SemanticAnalyzerPluginInterface # type: ignore[import] -from mypy.types import ProperType # type: ignore[import] - -def infer_type_from_right_hand_nameexpr( - api: SemanticAnalyzerPluginInterface, - stmt: AssignmentStmt, - node: Var, - left_hand_explicit_type: ProperType | None, - infer_from_right_side: RefExpr, -) -> ProperType | None: ... -def infer_type_from_left_hand_type_only( - api: SemanticAnalyzerPluginInterface, node: Var, left_hand_explicit_type: ProperType | None -) -> ProperType | None: ... -def extract_python_type_from_typeengine( - api: SemanticAnalyzerPluginInterface, node: TypeInfo, type_args: Sequence[Expression] -) -> ProperType: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi deleted file mode 100644 index 80a367e44051..000000000000 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi +++ /dev/null @@ -1,31 +0,0 @@ -# mypy_test can't find mypy import -from mypy.nodes import ClassDef, Expression, MemberExpr, NameExpr, SymbolNode, TypeInfo # type: ignore[import] -from mypy.plugin import SemanticAnalyzerPluginInterface # type: ignore[import] -from mypy.types import UnboundType # type: ignore[import] - -from ...util import symbol - -COLUMN: symbol -RELATIONSHIP: symbol -REGISTRY: symbol -COLUMN_PROPERTY: symbol -TYPEENGINE: symbol -MAPPED: symbol -DECLARATIVE_BASE: symbol -DECLARATIVE_META: symbol -MAPPED_DECORATOR: symbol -SYNONYM_PROPERTY: symbol -COMPOSITE_PROPERTY: symbol -DECLARED_ATTR: symbol -MAPPER_PROPERTY: symbol -AS_DECLARATIVE: symbol -AS_DECLARATIVE_BASE: symbol -DECLARATIVE_MIXIN: symbol -QUERY_EXPRESSION: symbol - -def has_base_type_id(info: TypeInfo, type_id: int) -> bool: ... -def mro_has_id(mro: list[TypeInfo], type_id: int) -> bool: ... -def type_id_for_unbound_type(type_: UnboundType, cls: ClassDef, api: SemanticAnalyzerPluginInterface) -> int | None: ... -def type_id_for_callee(callee: Expression) -> int | None: ... -def type_id_for_named_node(node: NameExpr | MemberExpr | SymbolNode) -> int | None: ... -def type_id_for_fullname(fullname: str) -> int | None: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/plugin.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/plugin.pyi deleted file mode 100644 index af760ab87900..000000000000 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/plugin.pyi +++ /dev/null @@ -1,17 +0,0 @@ -from collections.abc import Callable - -# mypy_test can't find mypy import -from mypy.nodes import MypyFile # type: ignore[import] -from mypy.plugin import AttributeContext, ClassDefContext, DynamicClassDefContext, Plugin # type: ignore[import] -from mypy.types import Type # type: ignore[import] - -class SQLAlchemyPlugin(Plugin): - def get_dynamic_class_hook(self, fullname: str) -> Callable[[DynamicClassDefContext], None] | None: ... - def get_customize_class_mro_hook(self, fullname: str) -> Callable[[ClassDefContext], None] | None: ... - def get_class_decorator_hook(self, fullname: str) -> Callable[[ClassDefContext], None] | None: ... - def get_metaclass_hook(self, fullname: str) -> Callable[[ClassDefContext], None] | None: ... - def get_base_class_hook(self, fullname: str) -> Callable[[ClassDefContext], None] | None: ... - def get_attribute_hook(self, fullname: str) -> Callable[[AttributeContext], Type] | None: ... - def get_additional_deps(self, file: MypyFile) -> list[tuple[int, str, int]]: ... - -def plugin(version: str) -> type[SQLAlchemyPlugin]: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi b/stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi deleted file mode 100644 index 445c49c877e4..000000000000 --- a/stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi +++ /dev/null @@ -1,41 +0,0 @@ -from collections.abc import Iterable, Iterator -from typing import Any, TypeVar, overload - -# mypy_test can't find mypy import -from mypy.nodes import CallExpr, Context, Expression, JsonDict, NameExpr, Statement, TypeInfo # type: ignore[import] -from mypy.plugin import ClassDefContext, DynamicClassDefContext, SemanticAnalyzerPluginInterface # type: ignore[import] -from mypy.types import Type # type: ignore[import] - -_TArgType = TypeVar("_TArgType", bound=CallExpr | NameExpr) - -class SQLAlchemyAttribute: - name: Any - line: Any - column: Any - type: Any - info: Any - def __init__(self, name: str, line: int, column: int, typ: Type | None, info: TypeInfo) -> None: ... - def serialize(self) -> JsonDict: ... - def expand_typevar_from_subtype(self, sub_type: TypeInfo) -> None: ... - @classmethod - def deserialize(cls, info: TypeInfo, data: JsonDict, api: SemanticAnalyzerPluginInterface) -> SQLAlchemyAttribute: ... - -def name_is_dunder(name): ... -def establish_as_sqlalchemy(info: TypeInfo) -> None: ... -def set_is_base(info: TypeInfo) -> None: ... -def get_is_base(info: TypeInfo) -> bool: ... -def has_declarative_base(info: TypeInfo) -> bool: ... -def set_has_table(info: TypeInfo) -> None: ... -def get_has_table(info: TypeInfo) -> bool: ... -def get_mapped_attributes(info: TypeInfo, api: SemanticAnalyzerPluginInterface) -> list[SQLAlchemyAttribute] | None: ... -def set_mapped_attributes(info: TypeInfo, attributes: list[SQLAlchemyAttribute]) -> None: ... -def fail(api: SemanticAnalyzerPluginInterface, msg: str, ctx: Context) -> None: ... -def add_global(ctx: ClassDefContext | DynamicClassDefContext, module: str, symbol_name: str, asname: str) -> None: ... -@overload -def get_callexpr_kwarg(callexpr: CallExpr, name: str, *, expr_types: None = ...) -> CallExpr | NameExpr | None: ... -@overload -def get_callexpr_kwarg(callexpr: CallExpr, name: str, *, expr_types: tuple[type[_TArgType], ...]) -> _TArgType | None: ... -def flatten_typechecking(stmts: Iterable[Statement]) -> Iterator[Statement]: ... -def unbound_to_instance(api: SemanticAnalyzerPluginInterface, typ: Type) -> Type: ... -def info_for_cls(cls, api: SemanticAnalyzerPluginInterface) -> TypeInfo | None: ... -def expr_to_mapped_constructor(expr: Expression) -> CallExpr: ... diff --git a/tests/pytype_exclude_list.txt b/tests/pytype_exclude_list.txt index b3df64f8cae3..5a857e22c161 100644 --- a/tests/pytype_exclude_list.txt +++ b/tests/pytype_exclude_list.txt @@ -109,11 +109,3 @@ stubs/SQLAlchemy/sqlalchemy/sql/selectable.pyi stubs/Flask-SQLAlchemy/flask_sqlalchemy/__init__.pyi stubs/Flask-SQLAlchemy/flask_sqlalchemy/model.pyi stubs/Flask-SQLAlchemy/flask_sqlalchemy/utils.pyi - -# mypy extensions -stubs/SQLAlchemy/sqlalchemy/ext/mypy/apply.pyi -stubs/SQLAlchemy/sqlalchemy/ext/mypy/decl_class.pyi -stubs/SQLAlchemy/sqlalchemy/ext/mypy/infer.pyi -stubs/SQLAlchemy/sqlalchemy/ext/mypy/names.pyi -stubs/SQLAlchemy/sqlalchemy/ext/mypy/plugin.pyi -stubs/SQLAlchemy/sqlalchemy/ext/mypy/util.pyi