MagicStack / asyncpg

A fast PostgreSQL Database Client Library for Python/asyncio.
Apache License 2.0
6.88k stars 399 forks source link

asyncpg.connect() type is Coroutine[Any, Any, Any] #1028

Open lukepighetti opened 1 year ago

lukepighetti commented 1 year ago

I was expecting asyncpg.connect() to have a concrete type, but I'm new to python and I may be overlooking something obvious. Thank you.

lukepighetti commented 1 year ago

I ended up having to walk the AST to find the Connection class, is there any reason why it's not exposed by default?

import asyncpg
from asyncpg.connection import Connection

async def get_postgres() -> Connection:
    client: Connection = await asyncpg.connect(
        user=settings.POSTGRES_USER,
        password=settings.POSTGRES_PASSWORD,
        database=settings.POSTGRES_DATABASE,
        host=settings.POSTGRES_HOST,
    )
    return client
}

https://github.com/MagicStack/asyncpg/blob/master/asyncpg/connection.py#L1795