summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/asyncio/session.py
diff options
context:
space:
mode:
authorSam Bull <aa6bs0@sambull.org>2022-11-19 19:38:04 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2022-11-21 12:01:56 -0500
commite43e240a0088ac429eb551c7ea1c537c266b4853 (patch)
tree7a5604931823414fc133cf04b04e4f6607904b7c /lib/sqlalchemy/ext/asyncio/session.py
parent46e6693cb3db445f18aa25d5e4ca613504bd12b3 (diff)
downloadsqlalchemy-e43e240a0088ac429eb551c7ea1c537c266b4853.tar.gz
Fix inferred type of async_sessionmaker
Improved the typing for :class:`.sessionmaker` and :class:`.asyncsessionmaker`, so that the default type of their return value will be :class:`.Session` or :class:`.AsyncSession`, without the need to type this explicitly. Previously, Mypy would not automaticaly infer these return types from its generic base. As part of this change, arguments for :class:`.Session`, :class:`.AsyncSession`, :class:`.sessionmaker` and :class:`.asyncsessionmaker` beyond the initial "bind" argument have been made keyword-only, which includes parameters that have always been documented as keyword arguments, such as :paramref:`.Session.autoflush`, :paramref:`.Session.class_`, etc. Pull request courtesy Sam Bull. Closes: #8842 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8842 Pull-request-sha: fa6d1a8468e98b40e12f82ed7ddaddc1fde060ac Change-Id: Iaaabc4572a87489d61617d970f62b9b50db4fac7
Diffstat (limited to 'lib/sqlalchemy/ext/asyncio/session.py')
-rw-r--r--lib/sqlalchemy/ext/asyncio/session.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/sqlalchemy/ext/asyncio/session.py b/lib/sqlalchemy/ext/asyncio/session.py
index 1956ea588..a74e87769 100644
--- a/lib/sqlalchemy/ext/asyncio/session.py
+++ b/lib/sqlalchemy/ext/asyncio/session.py
@@ -124,6 +124,7 @@ class AsyncSession(ReversibleProxy[Session]):
def __init__(
self,
bind: Optional[_AsyncSessionBind] = None,
+ *,
binds: Optional[Dict[_SessionBindKey, _AsyncSessionBind]] = None,
sync_session_class: Optional[Type[Session]] = None,
**kw: Any,
@@ -1436,9 +1437,35 @@ class async_sessionmaker(Generic[_AS]):
class_: Type[_AS]
+ @overload
+ def __init__(
+ self,
+ bind: Optional[_AsyncSessionBind] = ...,
+ *,
+ class_: Type[_AS],
+ autoflush: bool = ...,
+ expire_on_commit: bool = ...,
+ info: Optional[_InfoType] = ...,
+ **kw: Any,
+ ):
+ ...
+
+ @overload
+ def __init__(
+ self: "async_sessionmaker[AsyncSession]",
+ bind: Optional[_AsyncSessionBind] = ...,
+ *,
+ autoflush: bool = ...,
+ expire_on_commit: bool = ...,
+ info: Optional[_InfoType] = ...,
+ **kw: Any,
+ ):
+ ...
+
def __init__(
self,
bind: Optional[_AsyncSessionBind] = None,
+ *,
class_: Type[_AS] = AsyncSession, # type: ignore
autoflush: bool = True,
expire_on_commit: bool = True,