redis: Add _Encodable type alias (#8638)

This commit is contained in:
Nikita Sobolev
2022-08-29 14:38:22 +03:00
committed by GitHub
parent 6e985ef3de
commit d3cded7fc6
2 changed files with 6 additions and 5 deletions

View File

@@ -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]: ...

View File

@@ -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: