Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add return type to PoolAcquireContext.__aenter__ and rename attribute #1270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
TerSent wants to merge 1 commit into MagicStack:master
base: master
Choose a base branch
Loading
from TerSent:fix/pool-acquire-typing
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions asyncpg/pool.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand Down

AltStyle によって変換されたページ (->オリジナル) /