From 46952525fdf734fb0160eee5fc470f09f6150b0a Mon Sep 17 00:00:00 2001 From: AmisAdmin <34331297+amisadmin@users.noreply.github.com> Date: Tue, 9 Aug 2022 17:09:37 +0800 Subject: [PATCH] Fixed typing error in `session.get`. (#221) The type '_T' has been defined as the 'Union[Connection, Engine]' type in the 'Session' class. --- sqlalchemy-stubs/orm/session.pyi | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/sqlalchemy-stubs/orm/session.pyi b/sqlalchemy-stubs/orm/session.pyi index fb9bcd8..f03e96a 100644 --- a/sqlalchemy-stubs/orm/session.pyi +++ b/sqlalchemy-stubs/orm/session.pyi @@ -36,6 +36,7 @@ from ..sql import Executable from ..sql.base import Options _T = TypeVar("_T") +_M = TypeVar("_M") _TSession = TypeVar("_TSession", bound=Session) _TSessionNoIoTypingCommon = TypeVar( "_TSession", bound=_SessionNoIoTypingCommon @@ -150,7 +151,7 @@ class _SessionProtocol( def delete(self, instance: Any) -> None: ... def get( self, - entity: Type[_T], + entity: Type[_M], ident: Any, options: Optional[Sequence[Any]] = ..., populate_existing: bool = ..., @@ -159,13 +160,13 @@ class _SessionProtocol( ] = ..., identity_token: Optional[Any] = ..., execution_options: Optional[_ExecuteOptions] = ..., - ) -> Optional[_T]: ... + ) -> Optional[_M]: ... def merge( self, - instance: _T, + instance: _M, load: bool = ..., options: Optional[Sequence[Any]] = ..., - ) -> _T: ... + ) -> _M: ... def flush(self, objects: Optional[Collection[Any]] = ...) -> None: ... @classmethod def close_all(cls) -> None: ... # NOTE: Deprecated. @@ -376,7 +377,7 @@ class _SessionTypingCommon( def flush(self, objects: Optional[Collection[Any]] = ...) -> None: ... def get( self, - entity: Type[_T], + entity: Type[_M], ident: Any, options: Optional[Sequence[Any]] = ..., populate_existing: bool = ..., @@ -385,7 +386,7 @@ class _SessionTypingCommon( ] = ..., identity_token: Optional[Any] = ..., execution_options: Optional[_ExecuteOptions] = ..., - ) -> Optional[_T]: ... + ) -> Optional[_M]: ... def bulk_save_objects( self, objects: Sequence[Any], @@ -405,10 +406,10 @@ class _SessionTypingCommon( ) -> None: ... def merge( self, - instance: _T, + instance: _M, load: bool = ..., options: Optional[Sequence[Any]] = ..., - ) -> _T: ... + ) -> _M: ... def query(self, *entities: Any, **kwargs: Any) -> Query[Any]: ... def refresh( self,