-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Description
When our code calls register_script on a RedisCluster script, mypy flags the call as an error because the register_script method is defined like this in ScriptComamnds:
def register_script(self: "redis.client.Redis", script: ScriptTextT) -> Script:
# ... lines omitted ...
return Script(self, script)
I believe this was done because the Script class expects an object of type redis.client.Redis, but I'd imagine this could be solved by making Script accept Union[Redis, RedisCluster] instead.
Steps to Repro
- Create a file with these contents:
from typing import Union import redis from redis.commands.core import Script def load_script(redis_connection: Union[redis.Redis, redis.RedisCluster], script_filename: str) -> Script: with open(script_filename) as lua_script_file: lua_script_contents = lua_script_file.read() return redis_connection.register_script(lua_script_contents)
- Run mypy on the code.
Expected Results
No error from mypy.
Actual Results
mypy prints this error:
example.py:11: Invalid self argument "RedisCluster" to attribute function "register_script" with type "Callable[[Redis, Union[bytes, str, memoryview[int]]], Script]
Metadata
Metadata
Assignees
Labels
No labels