Skip to content
Latchkey

Python "TypeError: object X can't be used in await expression" in CI

The await keyword requires an awaitable (a coroutine, Task, or Future). Awaiting a plain value, a sync function's return, or a coroutine function reference (not its call) raises this TypeError.

What this error means

A test fails with "TypeError: object dict can't be used in 'await' expression" (or function, int, ...), pointing at an await on something that is not awaitable.

pytest
TypeError: object dict can't be used in 'await' expression

Common causes

Awaiting a synchronous result

A function that returns a plain value (not a coroutine) was awaited, which is not allowed.

Awaiting the function instead of its call

Writing await fn instead of await fn() awaits the function object itself, which is not awaitable.

How to fix it

Await only awaitables

  1. Confirm the target is async def or returns a coroutine/Future.
  2. Call the coroutine function so it returns a coroutine, then await it.
  3. Drop await from synchronous calls.
Python
# wrong: await sync result / await function object
# right:
result = await fetch()      # fetch is async def, called here
value = compute()           # sync: no await

Wrap blocking calls for the loop

To await a synchronous, blocking function, run it in a thread executor.

Python
import asyncio
result = await asyncio.to_thread(blocking_call, arg)

How to prevent it

  • Await only async def results, Tasks, or Futures.
  • Call coroutine functions (fn()) before awaiting them.
  • Use asyncio.to_thread to await blocking sync work.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →