From c5332880461eb0f5a4c22e7beb708cd8315e9a60 Mon Sep 17 00:00:00 2001 From: TsygulevAA Date: Sat, 16 Aug 2025 21:55:14 +0300 Subject: [PATCH] Add return type to PoolAcquireContext.__aenter__ and rename internal attribute --- asyncpg/pool.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/asyncpg/pool.py b/asyncpg/pool.py index 5c7ea9ca..9308de93 100644 --- a/asyncpg/pool.py +++ b/asyncpg/pool.py @@ -1042,19 +1042,19 @@ async def __aexit__(self, *exc): class PoolAcquireContext: - __slots__ = ('timeout', 'connection', 'done', 'pool') + __slots__ = ('timeout', '_conn', 'done', 'pool') def __init__(self, pool: Pool, timeout: Optional[float]) -> None: self.pool = pool self.timeout = timeout - self.connection = None + self._conn = None self.done = False - async def __aenter__(self): - if self.connection is not None or self.done: + async def __aenter__(self) -> connection.Connection: + if self._conn is not None or self.done: raise exceptions.InterfaceError('a connection is already acquired') - self.connection = await self.pool._acquire(self.timeout) - return self.connection + self._conn = await self.pool._acquire(self.timeout) + return self._conn async def __aexit__( self, @@ -1063,8 +1063,8 @@ async def __aexit__( exc_tb: Optional[TracebackType] = None, ) -> None: self.done = True - con = self.connection - self.connection = None + con = self._conn + self._conn = None await self.pool.release(con) def __await__(self):