maligree
maligree

Reputation: 6147

Python typing and Redis asyncio: telling the type checker to expect an Awaitable

Minimal example:

import redis.asyncio as redis

client = redis.Redis()
client.hset(key, mapping=...)

Pylance complains about it like so:

"int" is not awaitable
  "int" is incompatible with protocol "Awaitable[_T_co@Awaitable]"
    "__await__" is not presentPylancereportGeneralTypeIssues

hset is declared as (Awaitable[int] | int).

The simplest solution seems to be to cast(Awaitable, client.hset(...)). Is there any other, dry-er way to tell the type-checker that I am expecting all Redis commands to return an Awaitable so I don't have to cast() to Awaitable every time I touch Redis?

Upvotes: 0

Views: 16

Answers (0)

Related Questions