Skip to content

Commit 12bf2ac

Browse files
committed
fix: update type hints for provide_request_session methods to include DriverT
1 parent e020e3a commit 12bf2ac

File tree

1 file changed

+54
-8
lines changed

1 file changed

+54
-8
lines changed

sqlspec/extensions/litestar/plugin.py

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -581,18 +581,18 @@ def _create_session(
581581
@overload
582582
def provide_request_session(
583583
self,
584-
key: "SyncDatabaseConfig[Any, Any, Any] | NoPoolSyncConfig[Any, Any] | type[SyncDatabaseConfig[Any, Any, Any] | NoPoolSyncConfig[Any, Any]]",
584+
key: "SyncDatabaseConfig[Any, Any, DriverT] | NoPoolSyncConfig[Any, DriverT] | type[SyncDatabaseConfig[Any, Any, DriverT] | NoPoolSyncConfig[Any, DriverT]]",
585585
state: "State",
586586
scope: "Scope",
587-
) -> "SyncDriverAdapterBase": ...
587+
) -> "DriverT": ...
588588

589589
@overload
590590
def provide_request_session(
591591
self,
592-
key: "AsyncDatabaseConfig[Any, Any, Any] | NoPoolAsyncConfig[Any, Any] | type[AsyncDatabaseConfig[Any, Any, Any] | NoPoolAsyncConfig[Any, Any]]",
592+
key: "AsyncDatabaseConfig[Any, Any, DriverT] | NoPoolAsyncConfig[Any, DriverT] | type[AsyncDatabaseConfig[Any, Any, DriverT] | NoPoolAsyncConfig[Any, DriverT]]",
593593
state: "State",
594594
scope: "Scope",
595-
) -> "AsyncDriverAdapterBase": ...
595+
) -> "DriverT": ...
596596

597597
@overload
598598
def provide_request_session(
@@ -625,9 +625,31 @@ def provide_request_session(
625625
self._raise_missing_connection(plugin_state.connection_key)
626626
return self._create_session(plugin_state, connection, scope)
627627

628+
@overload
629+
def provide_request_session_sync(
630+
self,
631+
key: "SyncDatabaseConfig[Any, Any, DriverT] | NoPoolSyncConfig[Any, DriverT]",
632+
state: "State",
633+
scope: "Scope",
634+
) -> "DriverT": ...
635+
636+
@overload
637+
def provide_request_session_sync(
638+
self,
639+
key: "type[SyncDatabaseConfig[Any, Any, DriverT] | NoPoolSyncConfig[Any, DriverT]]",
640+
state: "State",
641+
scope: "Scope",
642+
) -> "DriverT": ...
643+
644+
@overload
645+
def provide_request_session_sync(self, key: str, state: "State", scope: "Scope") -> "SyncDriverAdapterBase": ...
646+
628647
def provide_request_session_sync(
629-
self, key: "str | SyncConfigT | type[SyncConfigT]", state: "State", scope: "Scope"
630-
) -> "SyncDriverAdapterBase":
648+
self,
649+
key: "str | SyncDatabaseConfig[Any, Any, Any] | NoPoolSyncConfig[Any, Any] | type[SyncDatabaseConfig[Any, Any, Any] | NoPoolSyncConfig[Any, Any]]",
650+
state: "State",
651+
scope: "Scope",
652+
) -> "SyncDriverAdapterBase | Any":
631653
"""Provide a sync database session for the specified configuration key from request scope.
632654
633655
If no connection exists in scope, one will be created from the pool and stored
@@ -647,9 +669,33 @@ def provide_request_session_sync(
647669
connection = self._ensure_connection(plugin_state, state, scope)
648670
return cast("SyncDriverAdapterBase", self._create_session(plugin_state, connection, scope))
649671

672+
@overload
673+
async def provide_request_session_async(
674+
self,
675+
key: "AsyncDatabaseConfig[Any, Any, DriverT] | NoPoolAsyncConfig[Any, DriverT]",
676+
state: "State",
677+
scope: "Scope",
678+
) -> "DriverT": ...
679+
680+
@overload
681+
async def provide_request_session_async(
682+
self,
683+
key: "type[AsyncDatabaseConfig[Any, Any, DriverT] | NoPoolAsyncConfig[Any, DriverT]]",
684+
state: "State",
685+
scope: "Scope",
686+
) -> "DriverT": ...
687+
688+
@overload
689+
async def provide_request_session_async(
690+
self, key: str, state: "State", scope: "Scope"
691+
) -> "AsyncDriverAdapterBase": ...
692+
650693
async def provide_request_session_async(
651-
self, key: "str | AsyncConfigT | type[AsyncConfigT]", state: "State", scope: "Scope"
652-
) -> "AsyncDriverAdapterBase":
694+
self,
695+
key: "str | AsyncDatabaseConfig[Any, Any, Any] | NoPoolAsyncConfig[Any, Any] | type[AsyncDatabaseConfig[Any, Any, Any] | NoPoolAsyncConfig[Any, Any]]",
696+
state: "State",
697+
scope: "Scope",
698+
) -> "AsyncDriverAdapterBase | Any":
653699
"""Provide an async database session for the specified configuration key from request scope.
654700
655701
If no connection exists in scope, one will be created from the pool and stored

0 commit comments

Comments
 (0)