-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
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
Best way to receive the return value when the type hint is Union[Awaitable[int], int]? #2399
Comments
That smells like a typing bug in the library. |
I'm also facing this issue. I there any update? def llen(self, name: str) -> Union[Awaitable[int], int]:
"""
Return the length of the list ``name``
For more information see https://redis.io/commands/llen
""" Many of the methods with |
Similarly for almost ALL functions in commands/core.py, they're annotated to return |
This issue is marked stale. It will be closed in 30 days if it is not updated. |
Still relevant, I presume |
I'm hitting this, but in the reverse; mypy complains when using the asyncio version that it might return int, even when I'm importing from redis.asyncio and calling |
I'm also facing the same issue. |
Seems like this should be mentioned here. One of the linked issues above contains a reply with a solution/workaround: The suggested solution is to install the type stub package: https://pypi.org/project/types-redis/ Worked for me 👍 Afaiu, this is the old way of getting typing hints for redis but the package now has its own typing hints that are incomplete. Because of that pylance won't tell you to go install available type stubs but it will complain because the included types return types are wrong. |
Thanks this has fixed it :) It's always a bit irritating when something as big as redis has typing support, but it's incomplete in a way that it fails for the most basic stuff. So I'll leave this here as a push :D |
For the latest version of
For
For
|
Exactly. I don't think Redis, Inc maintain this redis-py well, the code is bad typed in general and lots of issues seems to be neglected. May better for this project to delete the |
res = rdb.sadd(key, *values)
assert isinstance(res, Awaitable)
return await res Check the return value for its type to circumvent static checks. Of course, if you're not confident, you can also replace it with an 'if' statement. |
The type stubs at Perhaps the types should be dropped entirely from this project, as they are basically not usable & it seems there's no interest in improving them from Redis Labs, Inc? There's a few open pull requests that have been open for months with no traction.
Agreed, but typeshed removed it (partially because they are concerned about Redis Inc taking legal action against them?) -- so I don't think there will be movement to reintroduce them. |
Has anyone at Redis said anything about improving type hints for this package beyond the threatening legal action against typeshed? |
To clarify: No legal action or threats were sent out to typeshed to my knowledge. It was mostly concerns because there is a belief out in the wild that redis is "tightening their use of the trademark". The typeshed types weren't great, either - they were stuck on redis-py 4. According to the relevant typeshed issue, they were hoping for support or cooperation but hadn't seen any. And many issues relating to types are not really seeing feedback from anyone that is a maintainer that I can see. However, without feedback from a redis engineer / maintainer we don't have much as far as info on what their roadmap is. Some bug fixes & improvements for Redis enterprise features maybe? |
Ah my bad I thought they'd been threatened with legal action to protect the redis trademark |
I noticed the return value type hint of redis-py functions are always like: Union[Awaitable[int], int]: (e.g. redis.commands.core.py:L4824)
When I receive the value as normal
Pylance will remind me
How to let Pylance know I am not calling the function in asynchronous way, so I can mitigate this type checking error?
The text was updated successfully, but these errors were encountered: