redis: fix several stubtest warnings (#6378)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
Akuli
2021-12-01 12:00:07 +02:00
committed by GitHub
parent 7e22a9e34a
commit deaa764915
8 changed files with 78 additions and 52 deletions

View File

@@ -1,7 +1,3 @@
redis.client.Pipeline.client_list
redis.client.Pipeline.flushall
redis.client.Pipeline.flushdb
redis.client.Pipeline.hscan
redis.client.Pipeline.pubsub
redis.client.Pipeline.scan
redis.client.Pipeline.scan_iter
@@ -17,8 +13,6 @@ redis.client.PubSub.encode
redis.client.PubSub.execute_command
redis.client.PubSub.parse_response
redis.client.PubSub.run_in_thread
redis.client.Redis.flushall
redis.client.Redis.flushdb
redis.client.Redis.hscan
redis.client.Redis.pubsub
redis.client.Redis.scan
@@ -26,8 +20,3 @@ redis.client.Redis.scan_iter
redis.client.Redis.shutdown
redis.client.Redis.sscan
redis.client.pairs_to_dict
redis.connection.HIREDIS_SUPPORTS_BYTE_BUFFER
redis.connection.HIREDIS_SUPPORTS_CALLABLE_ERRORS
redis.connection.HIREDIS_USE_BYTE_BUFFER
redis.connection.hiredis_version
redis.connection.msg

View File

@@ -1,15 +1,25 @@
from . import client, connection, exceptions, utils
from . import client, connection, exceptions, sentinel, utils
Redis = client.Redis
StrictRedis = client.StrictRedis
BlockingConnectionPool = connection.BlockingConnectionPool
ConnectionPool = connection.ConnectionPool
Connection = connection.Connection
ConnectionPool = connection.ConnectionPool
SSLConnection = connection.SSLConnection
StrictRedis = client.StrictRedis
UnixDomainSocketConnection = connection.UnixDomainSocketConnection
from_url = utils.from_url
Sentinel = sentinel.Sentinel
SentinelConnectionPool = sentinel.SentinelConnectionPool
SentinelManagedConnection = sentinel.SentinelManagedConnection
SentinelManagedSSLConnection = sentinel.SentinelManagedSSLConnection
AuthenticationError = exceptions.AuthenticationError
AuthenticationWrongNumberOfArgsError = exceptions.AuthenticationWrongNumberOfArgsError
BusyLoadingError = exceptions.BusyLoadingError
ChildDeadlockedError = exceptions.ChildDeadlockedError
ConnectionError = exceptions.ConnectionError
DataError = exceptions.DataError
InvalidResponse = exceptions.InvalidResponse

View File

@@ -1,6 +1,8 @@
import builtins
import threading
from _typeshed import SupportsItems
from datetime import datetime, timedelta
from typing import Any, Callable, Generic, Iterable, Iterator, Mapping, Sequence, Type, TypeVar, Union, overload
from typing import Any, Callable, Dict, Generic, Iterable, Iterator, Mapping, Pattern, Sequence, Type, TypeVar, Union, overload
from typing_extensions import Literal
from .commands import CoreCommands, RedisModuleCommands, SentinelCommands
@@ -8,7 +10,28 @@ from .connection import ConnectionPool
from .lock import Lock
from .retry import Retry
_ScoreCastFuncReturn = TypeVar("_ScoreCastFuncReturn")
_Value = Union[bytes, float, int, str]
_Key = Union[str, bytes]
# Lib returns str or bytes depending on value of decode_responses
_StrType = TypeVar("_StrType", bound=Union[str, bytes])
_VT = TypeVar("_VT")
_T = TypeVar("_T")
class CaseInsensitiveDict(Dict[_StrType, _VT]):
def __init__(self, data: SupportsItems[_StrType, _VT]) -> None: ...
def update(self, data: SupportsItems[_StrType, _VT]) -> None: ... # type: ignore[override]
@overload
def get(self, k: _StrType, default: None = ...) -> _VT | None: ...
@overload
def get(self, k: _StrType, default: _VT | _T) -> _VT | _T: ...
# Overrides many other methods too, but without changing signature
SYM_EMPTY: Any
SENTINEL_STATE_TYPES: Any
def list_or_args(keys, args): ...
def timestamp_to_datetime(response): ...
@@ -16,9 +39,6 @@ def string_keys_to_dict(key_string, callback): ...
def parse_debug_object(response): ...
def parse_object(response, infotype): ...
def parse_info(response): ...
SENTINEL_STATE_TYPES: Any
def parse_sentinel_state(item): ...
def parse_sentinel_master(response): ...
def parse_sentinel_masters(response): ...
@@ -38,14 +58,6 @@ def parse_hscan(response, **options): ...
def parse_zscan(response, **options): ...
def parse_slowlog_get(response, **options): ...
_ScoreCastFuncReturn = TypeVar("_ScoreCastFuncReturn")
_Value = Union[bytes, float, int, str]
_Key = Union[str, bytes]
# Lib returns str or bytes depending on Python version and value of decode_responses
_StrType = TypeVar("_StrType", bound=Union[str, bytes])
_LockType = TypeVar("_LockType")
class Redis(RedisModuleCommands, CoreCommands[_StrType], SentinelCommands, Generic[_StrType]):
@@ -264,8 +276,6 @@ class Redis(RedisModuleCommands, CoreCommands[_StrType], SentinelCommands, Gener
def dbsize(self) -> int: ...
def debug_object(self, key): ...
def echo(self, value: _Value) -> bytes: ...
def flushall(self) -> bool: ...
def flushdb(self) -> bool: ...
def info(self, section: _Key | None = ...) -> Mapping[str, Any]: ...
def lastsave(self): ...
def object(self, infotype, key): ...
@@ -277,10 +287,6 @@ class Redis(RedisModuleCommands, CoreCommands[_StrType], SentinelCommands, Gener
def slowlog_len(self): ...
def slowlog_reset(self): ...
def time(self): ...
def append(self, key, value): ...
def bitcount(self, key: _Key, start: int | None = ..., end: int | None = ...) -> int: ...
def bitop(self, operation, dest, *keys): ...
def bitpos(self, key, bit, start=..., end=...): ...
def decr(self, name, amount=...) -> int: ...
def decrby(self, name, amount=...) -> int: ...
def delete(self, *names: _Key) -> int: ...
@@ -470,6 +476,15 @@ class PubSub:
def run_in_thread(self, sleep_time=...): ...
def ping(self, message: _Value | None = ...) -> None: ...
class PubSubWorkerThread(threading.Thread):
daemon: Any
pubsub: Any
sleep_time: Any
exception_handler: Any
def __init__(self, pubsub, sleep_time, daemon: bool = ..., exception_handler: Any | None = ...) -> None: ...
def run(self) -> None: ...
def stop(self) -> None: ...
class Pipeline(Redis[_StrType], Generic[_StrType]):
UNWATCH_COMMANDS: Any
connection_pool: Any
@@ -488,6 +503,7 @@ class Pipeline(Redis[_StrType], Generic[_StrType]):
def __del__(self) -> None: ...
def __len__(self) -> int: ...
def __bool__(self) -> bool: ...
def discard(self) -> None: ...
def reset(self) -> None: ...
def multi(self) -> None: ...
def execute_command(self, *args, **options): ...
@@ -531,7 +547,7 @@ class Pipeline(Redis[_StrType], Generic[_StrType]):
def bgsave(self, schedule: bool = ...) -> Pipeline[_StrType]: ... # type: ignore[override]
def client_id(self) -> Pipeline[_StrType]: ... # type: ignore[override]
def client_kill(self, address: str) -> Pipeline[_StrType]: ... # type: ignore[override]
def client_list(self) -> Pipeline[_StrType]: ... # type: ignore[override]
def client_list(self, _type: str | None = ..., client_id: list[str] = ...) -> Pipeline[_StrType]: ... # type: ignore[override]
def client_getname(self) -> Pipeline[_StrType]: ... # type: ignore[override]
def client_setname(self, name: str) -> Pipeline[_StrType]: ... # type: ignore[override]
def readwrite(self) -> Pipeline[_StrType]: ... # type: ignore[override]
@@ -543,8 +559,8 @@ class Pipeline(Redis[_StrType], Generic[_StrType]):
def dbsize(self) -> Pipeline[_StrType]: ... # type: ignore[override]
def debug_object(self, key) -> Pipeline[_StrType]: ... # type: ignore[override]
def echo(self, value) -> Pipeline[_StrType]: ... # type: ignore[override]
def flushall(self) -> Pipeline[_StrType]: ... # type: ignore[override]
def flushdb(self) -> Pipeline[_StrType]: ... # type: ignore[override]
def flushall(self, asynchronous: bool = ...) -> Pipeline[_StrType]: ... # type: ignore[override]
def flushdb(self, asynchronous: bool = ...) -> Pipeline[_StrType]: ... # type: ignore[override]
def info(self, section: _Key | None = ...) -> Pipeline[_StrType]: ... # type: ignore[override]
def lastsave(self) -> Pipeline[_StrType]: ... # type: ignore[override]
def object(self, infotype, key) -> Pipeline[_StrType]: ... # type: ignore[override]
@@ -656,7 +672,7 @@ class Pipeline(Redis[_StrType], Generic[_StrType]):
def scan_iter(self, match: str | None = ..., count: int | None = ...) -> Iterator[Any]: ...
def sscan(self, name: _Key, cursor: int = ..., match: str = ..., count: int = ...) -> Pipeline[_StrType]: ... # type: ignore[override]
def sscan_iter(self, name, match=..., count=...) -> Iterator[Any]: ...
def hscan(self, name: _Key, cursor: int = ..., match: str = ..., count: int = ...) -> Pipeline[_StrType]: ... # type: ignore[override]
def hscan(self, name: _Key, cursor: int = ..., match: str | None = ..., count: int | None = ...) -> Pipeline[_StrType]: ... # type: ignore[override]
def hscan_iter(self, name, match=..., count=...) -> Iterator[Any]: ...
def zscan(self, name, cursor=..., match=..., count=..., score_cast_func=...) -> Pipeline[_StrType]: ... # type: ignore[override]
def zscan_iter(self, name, match=..., count=..., score_cast_func=...) -> Iterator[Any]: ...
@@ -813,6 +829,8 @@ class Script:
def __call__(self, keys=..., args=..., client=...): ...
class Monitor(object):
command_re: Pattern[str]
monitor_re: Pattern[str]
def __init__(self, connection_pool) -> None: ...
def __enter__(self) -> Monitor: ...
def __exit__(self, *args: Any) -> None: ...

View File

@@ -31,13 +31,19 @@ class CoreCommands(Generic[_StrType]):
) -> bool: ...
def acl_users(self) -> list[str]: ...
def acl_whoami(self) -> str: ...
def append(self, key, value): ...
def bitcount(self, key: _Key, start: int | None = ..., end: int | None = ...) -> int: ...
def bitop(self, operation, dest, *keys): ...
def bitpos(self, key, bit, start=..., end=...): ...
def bgrewriteaof(self): ...
def bgsave(self, schedule: bool = ...): ...
def client_id(self) -> int: ...
def client_kill(self, address: str) -> bool: ...
def client_list(self, _type: Any | None = ..., client_id=...) -> list[dict[str, str]]: ...
def client_list(self, _type: str | None = ..., client_id: list[str] = ...) -> list[dict[str, str]]: ...
def client_getname(self) -> str | None: ...
def client_setname(self, name: str) -> bool: ...
def flushall(self, asynchronous: bool = ...) -> bool: ...
def flushdb(self, asynchronous: bool = ...) -> bool: ...
def lindex(self, name: _Key, index: int) -> _StrType | None: ...
def linsert(
self, name: _Key, where: Literal["BEFORE", "AFTER", "before", "after"], refvalue: _Value, value: _Value

View File

@@ -3,11 +3,6 @@ from typing import Any, Mapping, Type
from .retry import Retry
ssl_available: Any
hiredis_version: Any
HIREDIS_SUPPORTS_CALLABLE_ERRORS: Any
HIREDIS_SUPPORTS_BYTE_BUFFER: Any
msg: Any
HIREDIS_USE_BYTE_BUFFER: Any
SYM_STAR: Any
SYM_DOLLAR: Any
SYM_CRLF: Any
@@ -152,8 +147,6 @@ class UnixDomainSocketConnection(Connection):
) -> None: ...
def repr_pieces(self) -> list[tuple[str, str]]: ...
def to_bool(value: object) -> bool: ...
class ConnectionPool:
@classmethod
def from_url(cls, url: str, *, db: int = ..., decode_components: bool = ..., **kwargs) -> ConnectionPool: ...
@@ -181,3 +174,6 @@ class BlockingConnectionPool(ConnectionPool):
def get_connection(self, command_name, *keys, **options): ...
def release(self, connection): ...
def disconnect(self): ...
def to_bool(value: object) -> bool: ...
def parse_url(url: str) -> dict[str, Any]: ...

View File

@@ -1,7 +1,4 @@
class RedisError(Exception): ...
def __unicode__(self): ...
class AuthenticationError(RedisError): ...
class ConnectionError(RedisError): ...
class TimeoutError(RedisError): ...
@@ -15,6 +12,7 @@ class NoScriptError(ResponseError): ...
class ExecAbortError(ResponseError): ...
class ReadOnlyError(ResponseError): ...
class NoPermissionError(ResponseError): ...
class ModuleError(ResponseError): ...
class LockError(RedisError, ValueError): ...
class LockNotOwnedError(LockError): ...
class ChildDeadlockedError(Exception): ...

View File

@@ -1,5 +1,5 @@
from types import TracebackType
from typing import Any, Type
from typing import Any, ClassVar, Type
from typing_extensions import Protocol
from redis.client import Redis
@@ -8,6 +8,12 @@ class _Local(Protocol):
token: str | bytes | None
class Lock:
LUA_EXTEND_SCRIPT: ClassVar[str]
LUA_REACQUIRE_SCRIPT: ClassVar[str]
LUA_RELEASE_SCRIPT: ClassVar[str]
lua_extend: ClassVar[Any | None]
lua_reacquire: ClassVar[Any | None]
lua_release: ClassVar[Any | None]
local: _Local
def __init__(
self,

View File

@@ -1,7 +1,9 @@
from typing import Any, Type, TypeVar, overload
from typing_extensions import Literal
from redis.client import Redis
from redis.connection import Connection, ConnectionPool
from redis.commands.sentinel import SentinelCommands
from redis.connection import Connection, ConnectionPool, SSLConnection
from redis.exceptions import ConnectionError
_Redis = TypeVar("_Redis", bound=Redis[Any])
@@ -16,6 +18,8 @@ class SentinelManagedConnection(Connection):
def connect(self) -> None: ...
def read_response(self): ...
class SentinelManagedSSLConnection(SentinelManagedConnection, SSLConnection): ...
class SentinelConnectionPool(ConnectionPool):
is_master: bool
check_connection: bool
@@ -28,9 +32,7 @@ class SentinelConnectionPool(ConnectionPool):
def get_master_address(self): ...
def rotate_slaves(self): ...
# TODO: this should subclass `redis.commands.SentinelCommands` in the future
# right now `redis.commands` is missing.
class Sentinel(object):
class Sentinel(SentinelCommands):
sentinel_kwargs: Any
sentinels: Any
min_other_sentinels: int
@@ -50,3 +52,4 @@ class Sentinel(object):
def slave_for(self, service_name: str, connection_pool_class=..., **kwargs) -> Redis[Any]: ...
@overload
def slave_for(self, service_name: str, redis_class: Type[_Redis] = ..., connection_pool_class=..., **kwargs) -> _Redis: ...
def execute_command(self, *args, **kwargs) -> Literal[True]: ...