Skip to content

ResponseT shouldn't be async when using sync Redis class #3497

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

Closed
patrick91 opened this issue Feb 3, 2025 · 4 comments
Closed

ResponseT shouldn't be async when using sync Redis class #3497

patrick91 opened this issue Feb 3, 2025 · 4 comments

Comments

@patrick91
Copy link
Contributor

This code here:

from typing import reveal_type

from redis import Redis

redis = Redis(host="localhost", port=6379, db=0)

redis.set("test", "Hello, World!")

reveal_type(redis.get("test"))

Shows:

Revealed type is "Union[typing.Awaitable[Any], Any]"

Which I think is wrong, since the return type should be Any instead[1], right?

I think we might separate ResponseT for Redis and async Redis, what do you think?

I haven't sent a PR for this, because it will touch quite a few files, so I wanted to double check with you all first 😊

[1] We should allow using generics for return types, but that's another issue 😊

@vladvildanov
Copy link
Collaborator

@patrick91 Hey, thanks for reaching out! The problem is that both of clients sync and async uses the same RedisCommands class that define an API of commands itself, that's why it generic to satisfy both

@rafales
Copy link

rafales commented Feb 12, 2025

@vladvildanov at this point you may as well remove py.typed and strip annotations because it's useless - you get type errors every time you want to use returned value.

You could also use generics for this which should work pretty well.

@mvanderlee
Copy link

Agreed. Incorrect types is worse than no types.
Commit to either.

@patrick91
Copy link
Contributor Author

@rafales @mvanderlee do you have time to send a PR to fix this issue? I've been meaning too but got busy with other projects 😊

But I think it should be doable and hopefully @vladvildanov will like the approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants