redis-py
redis-py copied to clipboard
Wrong typing for client parameters in Script
Version
5.0.1
Platform
Python 3.12.1 macOS 14.3
Description
The arguments referring to a client in the Script class are type annotated to the Redis class, although instances of RedisCluster can also end up being the client. This also applies to the ScriptCommands.register_script function, where it expects self to be a Redis instance, even though I can run this successfully with a RedisCluster client.
Causes the following type error:
Cannot access member "register_script" for type "RedisCluster"
Could not bind method "register_script" because "RedisCluster" is not assignable to parameter "self"
"RedisCluster" is incompatible with "Redis" Pylance (reportGeneralTypeIssues)
Code
from redis import Redis
from redis.cluster import RedisCluster
client = Redis("localhost")
script = client.register_script("""return redis.call("SET", KEYS[1], ARGV[1])""")
script(["mykey"], ["myvalue"])
client = RedisCluster("localhost")
script = client.register_script("""return redis.call("SET", KEYS[1], ARGV[1])""")
script(["mykey"], ["myvalue"]) # Type error
This issue is marked stale. It will be closed in 30 days if it is not updated.
Ah, staleness bots: because bugs just go away on their own if you ignore them! 🙉