Skip to content

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

Open
TerSent wants to merge 1 commit into
MagicStack:masterfrom
TerSent:fix/pool-acquire-typing
Open

Add return type to PoolAcquireContext.__aenter__ and rename attribute#1270
TerSent wants to merge 1 commit into
MagicStack:masterfrom
TerSent:fix/pool-acquire-typing

Conversation

@TerSent

@TerSent TerSent commented Aug 16, 2025

Copy link
Copy Markdown

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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant