redis-py icon indicating copy to clipboard operation
redis-py copied to clipboard

Wrong typing for client parameters in Script

Open abbasyadollahi opened this issue 1 year ago • 2 comments

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

abbasyadollahi avatar Jan 26 '24 02:01 abbasyadollahi

This issue is marked stale. It will be closed in 30 days if it is not updated.

github-actions[bot] avatar Mar 15 '25 00:03 github-actions[bot]

Ah, staleness bots: because bugs just go away on their own if you ignore them! 🙉

bcmills avatar Mar 16 '25 13:03 bcmills