-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Open
Description
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 errorbcmills
Metadata
Metadata
Assignees
Labels
No labels