asyncpg icon indicating copy to clipboard operation
asyncpg copied to clipboard

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

Open lukepighetti opened this issue 1 year ago • 1 comments

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 avatar Apr 27 '23 22:04 lukepighetti

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

lukepighetti avatar Apr 27 '23 22:04 lukepighetti