[Python] How to fix "Coroutine object is not callable" type hint warning?

Discussão em 'Python' iniciado por Stack, Julho 7, 2025.

  1. Stack

    Stack Membro Participativo

    I'm having troubles with type hinting in my async pytest fixtures. Fixture 1:

    @pytest.fixture(scope='function')
    async def create_raw_user(asyncpg_pool) -> Callable[[str, str, str], Awaitable[None]]:
    async def create_raw_user(email: str, name: str, password: str) -> None:
    auth = AuthHandler()
    hashed_password = auth.get_password_hash(password)
    async with asyncpg_pool.acquire() as connection:
    return await connection.execute(
    "INSERT INTO users (email, name, password, registered_at, auth0_registered) VALUES ('%s', '%s', '%s', '%s', '%s')"
    % (email, name, hashed_password, datetime.utcnow(), False)
    )

    return create_raw_user



    Fixture 2:

    @pytest.fixture(scope="function")
    async def create_user_instance(create_raw_user) -> Callable[[str, str, str], Awaitable[dict[str, Any]]]:
    async def create_user_instance(email: str = "test@email.com",
    name: str = "ilya",
    password: str = "password123") -> dict[str, Any]:
    await create_raw_user(email=email, name=name, password=password)
    return {
    "email": email,
    "name": name,
    "password": password
    }

    return create_user_instance


    The Pycharm warning occurs in the second fixture and in tests functions: [​IMG]

    [[​IMG]

    Tried to follow the recommendations from these sources, but it didn't really help: The right way to type hint a Coroutine function? https://github.com/python/typing/issues/424

    Continue reading...

Compartilhe esta Página