Skip to content

Commit d3cded7

Browse files
authored
redis: Add _Encodable type alias (#8638)
1 parent 6e985ef commit d3cded7

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

stubs/redis/redis/cluster.pyi

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ from typing_extensions import Literal
88
from redis.client import CaseInsensitiveDict, PubSub, Redis, _ParseResponseOptions
99
from redis.commands import CommandsParser, RedisClusterCommands
1010
from redis.commands.core import _StrType
11-
from redis.connection import BaseParser, Connection, ConnectionPool, Encoder, _ConnectionPoolOptions
11+
from redis.connection import BaseParser, Connection, ConnectionPool, Encoder, _ConnectionPoolOptions, _Encodable
1212
from redis.exceptions import MovedError, RedisError
1313
from redis.typing import EncodableT
1414

@@ -86,8 +86,7 @@ class RedisCluster(AbstractRedisCluster, RedisClusterCommands[_StrType], Generic
8686
def get_replicas(self) -> list[ClusterNode]: ...
8787
def get_random_node(self) -> ClusterNode: ...
8888
def get_nodes(self) -> list[ClusterNode]: ...
89-
# TODO: use type alias for `str | bytes | memoryview | bool | float`
90-
def get_node_from_key(self, key: str | bytes | memoryview | bool | float, replica: bool = ...) -> ClusterNode | None: ...
89+
def get_node_from_key(self, key: _Encodable, replica: bool = ...) -> ClusterNode | None: ...
9190
def get_default_node(self) -> ClusterNode | None: ...
9291
def set_default_node(self, node: ClusterNode | None) -> bool: ...
9392
def monitor(self, target_node: Any | None = ...): ...
@@ -103,7 +102,7 @@ class RedisCluster(AbstractRedisCluster, RedisClusterCommands[_StrType], Generic
103102
lock_class: type[Incomplete] | None = ...,
104103
thread_local: bool = ...,
105104
): ...
106-
def keyslot(self, key: str | bytes | memoryview | bool | float) -> int: ...
105+
def keyslot(self, key: _Encodable) -> int: ...
107106
def determine_slot(self, *args): ...
108107
def get_encoder(self) -> Encoder: ...
109108
def get_connection_kwargs(self) -> dict[str, Any]: ...

stubs/redis/redis/connection.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ class HiredisParser(BaseParser):
6868

6969
DefaultParser: type[BaseParser] # Hiredis or PythonParser
7070

71+
_Encodable: TypeAlias = str | bytes | memoryview | bool | float
72+
7173
class Encoder:
7274
encoding: str
7375
encoding_errors: str
7476
decode_responses: bool
7577
def __init__(self, encoding: str, encoding_errors: str, decode_responses: bool) -> None: ...
76-
def encode(self, value: str | bytes | memoryview | bool | float) -> bytes: ...
78+
def encode(self, value: _Encodable) -> bytes: ...
7779
def decode(self, value: str | bytes | memoryview, force: bool = ...) -> str: ...
7880

7981
class Connection:

0 commit comments

Comments
 (0)