We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Version: What redis-py and what redis version is the issue happening on? 5.0.2
Platform: What platform / version? (For example Python 3.5.1 on Windows 7 / Ubuntu 15.10 / Azure) 3.12
Description: Description of your issue, stack traces from errors and code that reproduces the issue
Pylance throws a type checking issue while trying to use await with hset using a redis.asyncio.client.Redis instance
"int" is not awaitable "int" is incompatible with protocol "Awaitable[_T_co@Awaitable]" "__await__" is not presentPylance[reportGeneralTypeIssues](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportGeneralTypeIssues) (method) def hset( name: str, key: str | None = None, value: str | None = None, mapping: dict[Unknown, Unknown] | None = None, items: list[Unknown] | None = None ) -> (Awaitable[int] | int)
import redis.asyncio as aio_redis pool = aio_redis.ConnectionPool.from_url( f"redis://{settings.redis_host}:{settings.redis_port}/{settings.redis_db}" ) client = await aio_redis.Redis.from_pool(pool) await client.hset(key, field, publish_data_json) # <--- pylance type check error here
Is this working as intended?
The text was updated successfully, but these errors were encountered:
I have the exact same issue. The async client is not typed and instead relies on the core commands, for example hset defined here:
redis-py/redis/commands/core.py
Lines 5000 to 5007 in 9df2225
Notice the Union[Awaitable[int], int]. Then the async client extends from this alias class:
Union[Awaitable[int], int]
Line 5087 in 9df2225
Now pyright (and pylance) complain because it still thinks that either of the two options is a possibility, when it actually isn't.
The solution would be to define the actual AsyncHashCommands class and add each method as async def but that sounds like a lot of work 😛
AsyncHashCommands
async def
I've decided to live with it and simply # type: ignore it
# type: ignore
Edit:
Alternatively, you can use inspect.isawaitable and act accordingly:
inspect.isawaitable
if inspect.isawaitable(rset := self._redis.set(key, data)): await rset
Sorry, something went wrong.
Related issue here (but non async): #2399
No branches or pull requests
Version: What redis-py and what redis version is the issue happening on?
5.0.2
Platform: What platform / version? (For example Python 3.5.1 on Windows 7 / Ubuntu 15.10 / Azure)
3.12
Description: Description of your issue, stack traces from errors and code that reproduces the issue
Pylance throws a type checking issue while trying to use await with hset using a redis.asyncio.client.Redis instance
Is this working as intended?
The text was updated successfully, but these errors were encountered: