Skip to content

Wrong typing for client parameters in Script #3123

@abbasyadollahi

Description

@abbasyadollahi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions