diff --git a/stubs/redis/redis/cluster.pyi b/stubs/redis/redis/cluster.pyi index f5510eb9e..19277243a 100644 --- a/stubs/redis/redis/cluster.pyi +++ b/stubs/redis/redis/cluster.pyi @@ -8,7 +8,7 @@ from typing_extensions import Literal from redis.client import CaseInsensitiveDict, PubSub, Redis, _ParseResponseOptions from redis.commands import CommandsParser, RedisClusterCommands from redis.commands.core import _StrType -from redis.connection import BaseParser, Connection, ConnectionPool, Encoder, _ConnectionPoolOptions +from redis.connection import BaseParser, Connection, ConnectionPool, Encoder, _ConnectionPoolOptions, _Encodable from redis.exceptions import MovedError, RedisError from redis.typing import EncodableT @@ -86,8 +86,7 @@ class RedisCluster(AbstractRedisCluster, RedisClusterCommands[_StrType], Generic def get_replicas(self) -> list[ClusterNode]: ... def get_random_node(self) -> ClusterNode: ... def get_nodes(self) -> list[ClusterNode]: ... - # TODO: use type alias for `str | bytes | memoryview | bool | float` - def get_node_from_key(self, key: str | bytes | memoryview | bool | float, replica: bool = ...) -> ClusterNode | None: ... + def get_node_from_key(self, key: _Encodable, replica: bool = ...) -> ClusterNode | None: ... def get_default_node(self) -> ClusterNode | None: ... def set_default_node(self, node: ClusterNode | None) -> bool: ... def monitor(self, target_node: Any | None = ...): ... @@ -103,7 +102,7 @@ class RedisCluster(AbstractRedisCluster, RedisClusterCommands[_StrType], Generic lock_class: type[Incomplete] | None = ..., thread_local: bool = ..., ): ... - def keyslot(self, key: str | bytes | memoryview | bool | float) -> int: ... + def keyslot(self, key: _Encodable) -> int: ... def determine_slot(self, *args): ... def get_encoder(self) -> Encoder: ... def get_connection_kwargs(self) -> dict[str, Any]: ... diff --git a/stubs/redis/redis/connection.pyi b/stubs/redis/redis/connection.pyi index 88237fb01..cec6df8aa 100644 --- a/stubs/redis/redis/connection.pyi +++ b/stubs/redis/redis/connection.pyi @@ -68,12 +68,14 @@ class HiredisParser(BaseParser): DefaultParser: type[BaseParser] # Hiredis or PythonParser +_Encodable: TypeAlias = str | bytes | memoryview | bool | float + class Encoder: encoding: str encoding_errors: str decode_responses: bool def __init__(self, encoding: str, encoding_errors: str, decode_responses: bool) -> None: ... - def encode(self, value: str | bytes | memoryview | bool | float) -> bytes: ... + def encode(self, value: _Encodable) -> bytes: ... def decode(self, value: str | bytes | memoryview, force: bool = ...) -> str: ... class Connection: