Skip to content
Discussion options

You must be logged in to vote

I'm the author of asyncpg-stubs. Your best bet will be to do one of the following:

Option 1: use dict-like access and trick the type checker to think your class is both TypedDict and asyncpg.Record

# types.py:
from typing import TYPE_CHECKING, TypedDict

import asyncpg

if TYPE_CHECKING:

    class Record(asyncpg.Record, TypedDict): ...  # pyright: ignore
else:
    Record = asyncpg.Record

# another_module.py:
from .types import Record

class MyRecord(Record):
    id: int
    username: str
    password: str

async def do_something() -> None:
    row = await conn.fetchrow("SELECT id, username, password FROM users WHERE id = $1", user_id, record_class=MyRecord)
    assert_type(row['id'], int)

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@iyad-f
Comment options

Comment options

You must be logged in to vote
3 replies
@iyad-f
Comment options

@bryanforbes
Comment options

@iyad-f
Comment options

Answer selected by iyad-f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants