asyncpg icon indicating copy to clipboard operation
asyncpg copied to clipboard

Add return type to PoolAcquireContext.__aenter__ and rename attribute

Open TerSent opened this issue 4 months ago • 0 comments

Summary

Improves type inference in async with pool.acquire() by:

  1. Adding -> connection.Connection return type to PoolAcquireContext.__aenter__
  2. Renaming internal attribute self.connection to self._conn to avoid confusion and help type checkers

Motivation

Without this change, type checkers (mypy, pyright, pylance) cannot correctly infer the type of the connection in:

async with pool.acquire() as conn:
    await conn.fetchrow("SELECT 1")  # ← conn has type 'Unknown' or 'Any'

TerSent avatar Aug 16 '25 19:08 TerSent