7
7
from __future__ import annotations
8
8
9
9
import asyncio
10
- from collections .abc import Awaitable , Callable
10
+ from collections .abc import Awaitable , Callable , Iterator
11
11
import functools
12
12
import inspect
13
13
import logging
@@ -405,7 +405,7 @@ def __init__(self, *connect_args,
405
405
self ._holders = []
406
406
self ._initialized = False
407
407
self ._initializing = False
408
- self ._queue = None
408
+ self ._queue : Optional [ asyncio . LifoQueue [ PoolConnectionHolder ]] = None
409
409
410
410
self ._connection_class = connection_class
411
411
self ._record_class = record_class
@@ -838,7 +838,11 @@ async def copy_records_to_table(
838
838
where = where
839
839
)
840
840
841
- def acquire (self , * , timeout = None ):
841
+ def acquire (
842
+ self ,
843
+ * ,
844
+ timeout : Optional [float ] = None ,
845
+ ) -> PoolAcquireContext :
842
846
"""Acquire a database connection from the pool.
843
847
844
848
:param float timeout: A timeout for acquiring a Connection.
@@ -863,11 +867,12 @@ def acquire(self, *, timeout=None):
863
867
"""
864
868
return PoolAcquireContext (self , timeout )
865
869
866
- async def _acquire (self , timeout ):
867
- async def _acquire_impl ():
868
- ch = await self ._queue .get () # type: PoolConnectionHolder
870
+ async def _acquire (self , timeout : Optional [float ]) -> PoolConnectionProxy :
871
+ async def _acquire_impl () -> PoolConnectionProxy :
872
+ assert self ._queue is not None
873
+ ch = await self ._queue .get ()
869
874
try :
870
- proxy = await ch .acquire () # type: PoolConnectionProxy
875
+ proxy = await ch .acquire ()
871
876
except (Exception , asyncio .CancelledError ):
872
877
self ._queue .put_nowait (ch )
873
878
raise
@@ -1039,7 +1044,7 @@ def __init__(self, pool: Pool, timeout: Optional[float]) -> None:
1039
1044
self .connection = None
1040
1045
self .done = False
1041
1046
1042
- async def __aenter__ (self ):
1047
+ async def __aenter__ (self ) -> PoolConnectionProxy :
1043
1048
if self .connection is not None or self .done :
1044
1049
raise exceptions .InterfaceError ('a connection is already acquired' )
1045
1050
self .connection = await self .pool ._acquire (self .timeout )
@@ -1056,7 +1061,7 @@ async def __aexit__(
1056
1061
self .connection = None
1057
1062
await self .pool .release (con )
1058
1063
1059
- def __await__ (self ):
1064
+ def __await__ (self ) -> Iterator [ PoolConnectionProxy ] :
1060
1065
self .done = True
1061
1066
return self .pool ._acquire (self .timeout ).__await__ ()
1062
1067
0 commit comments