Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Fix typing on blpop (etc) timeout argument #1224

Merged
merged 1 commit into from Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/1224.bugfix
@@ -0,0 +1 @@
Fix typing on blpop (etc) timeout argument
11 changes: 6 additions & 5 deletions aioredis/client.py
Expand Up @@ -65,6 +65,7 @@
ConsumerT = _StringLikeT # Consumer name
StreamIdT = Union[int, _StringLikeT]
ScriptTextT = _StringLikeT
TimeoutSecT = Union[int, float, _StringLikeT]
# Mapping is not covariant in the key type, which prevents
# Mapping[_StringLikeT, X from accepting arguments of type Dict[str, X]. Using
# a TypeVar instead of a Union allows mappings with any of the permitted types
Expand Down Expand Up @@ -2124,7 +2125,7 @@ def unlink(self, *names: KeyT) -> Awaitable:
return self.execute_command("UNLINK", *names)

# LIST COMMANDS
def blpop(self, keys: KeysT, timeout: int = 0) -> Awaitable:
def blpop(self, keys: KeysT, timeout: TimeoutSecT = 0) -> Awaitable:
"""
LPOP a value off of the first non-empty list
named in the ``keys`` list.
Expand All @@ -2137,7 +2138,7 @@ def blpop(self, keys: KeysT, timeout: int = 0) -> Awaitable:
"""
return self.execute_command("BLPOP", *list_or_args(keys, (timeout,)))

def brpop(self, keys: KeysT, timeout: int = 0) -> Awaitable:
def brpop(self, keys: KeysT, timeout: TimeoutSecT = 0) -> Awaitable:
"""
RPOP a value off of the first non-empty list
named in the ``keys`` list.
Expand All @@ -2150,7 +2151,7 @@ def brpop(self, keys: KeysT, timeout: int = 0) -> Awaitable:
"""
return self.execute_command("BRPOP", *list_or_args(keys, (timeout,)))

def brpoplpush(self, src: KeyT, dst: KeyT, timeout: int = 0) -> Awaitable:
def brpoplpush(self, src: KeyT, dst: KeyT, timeout: TimeoutSecT = 0) -> Awaitable:
"""
Pop a value off the tail of ``src``, push it on the head of ``dst``
and then return it.
Expand Down Expand Up @@ -3140,7 +3141,7 @@ def zpopmin(self, name: KeyT, count: Optional[int] = None) -> Awaitable:
options = {"withscores": True}
return self.execute_command("ZPOPMIN", name, *args, **options)

def bzpopmax(self, keys: KeysT, timeout: int = 0) -> Awaitable:
def bzpopmax(self, keys: KeysT, timeout: TimeoutSecT = 0) -> Awaitable:
"""
ZPOPMAX a value off of the first non-empty sorted set
named in the ``keys`` list.
Expand All @@ -3154,7 +3155,7 @@ def bzpopmax(self, keys: KeysT, timeout: int = 0) -> Awaitable:
parsed_keys = list_or_args(keys, (timeout,))
return self.execute_command("BZPOPMAX", *parsed_keys)

def bzpopmin(self, keys: KeysT, timeout: int = 0) -> Awaitable:
def bzpopmin(self, keys: KeysT, timeout: TimeoutSecT = 0) -> Awaitable:
"""
ZPOPMIN a value off of the first non-empty sorted set
named in the ``keys`` list.
Expand Down
10 changes: 7 additions & 3 deletions tests/conftest.py
Expand Up @@ -2,6 +2,7 @@
import asyncio
import random
from distutils.version import StrictVersion
from typing import Callable, TypeVar
from urllib.parse import urlparse

import pytest
Expand All @@ -25,6 +26,9 @@
REDIS_INFO = {}
default_redis_url = "redis://localhost:6379/9"

_DecoratedTest = TypeVar("_DecoratedTest", bound="Callable")
_TestDecorator = Callable[[_DecoratedTest], _DecoratedTest]


# Taken from python3.9
class BooleanOptionalAction(argparse.Action):
Expand Down Expand Up @@ -111,19 +115,19 @@ def pytest_sessionstart(session):
REDIS_INFO["arch_bits"] = arch_bits


def skip_if_server_version_lt(min_version):
def skip_if_server_version_lt(min_version: str) -> _TestDecorator:
redis_version = REDIS_INFO["version"]
check = StrictVersion(redis_version) < StrictVersion(min_version)
return pytest.mark.skipif(check, reason=f"Redis version required >= {min_version}")


def skip_if_server_version_gte(min_version):
def skip_if_server_version_gte(min_version: str) -> _TestDecorator:
redis_version = REDIS_INFO["version"]
check = StrictVersion(redis_version) >= StrictVersion(min_version)
return pytest.mark.skipif(check, reason=f"Redis version required < {min_version}")


def skip_unless_arch_bits(arch_bits):
def skip_unless_arch_bits(arch_bits: int) -> _TestDecorator:
return pytest.mark.skipif(
REDIS_INFO["arch_bits"] != arch_bits,
reason=f"server is not {arch_bits}-bit",
Expand Down