From 93e2806232617b7fa8207dac59b9d6f87e0df5bc Mon Sep 17 00:00:00 2001 From: Christopher Dignam Date: Thu, 4 Feb 2021 23:32:34 -0500 Subject: [PATCH] [redis] add overload for blpop and brpop timeout (#4998) 0 is the default value for the timeout argument for both blpop and brpop. When the timeout is `0`, the return type is non-nullable. Otherwise the return type is optional. I tested my change with the following code ```python from typing import Optional, Tuple import redis def test_blpop_timeout(r: redis.Redis) -> None: a: Tuple[bytes, bytes] = r.blpop('') b: Tuple[bytes, bytes] = r.blpop('',timeout=0) c: Optional[Tuple[bytes, bytes]] = r.blpop('', timeout=1) d: Optional[Tuple[bytes, bytes]] = r.blpop('', timeout=1.0) def test_brpop_timeout(r: redis.Redis) -> None: a: Tuple[bytes, bytes] = r.brpop('') b: Tuple[bytes, bytes] = r.brpop('',timeout=0) c: Optional[Tuple[bytes, bytes]] = r.brpop('', timeout=1) d: Optional[Tuple[bytes, bytes]] = r.brpop('', timeout=1.0) ``` --- stubs/redis/redis/client.pyi | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/stubs/redis/redis/client.pyi b/stubs/redis/redis/client.pyi index 7c58ed786..33fe9fdcd 100644 --- a/stubs/redis/redis/client.pyi +++ b/stubs/redis/redis/client.pyi @@ -473,8 +473,14 @@ class Redis(Generic[_StrType]): def watch(self, *names): ... def unlink(self, *names: _Key) -> int: ... def unwatch(self): ... - def blpop(self, keys: Union[_Value, Iterable[_Value]], timeout: float = ...) -> Optional[Tuple[_StrType, _StrType]]: ... - def brpop(self, keys: Union[_Value, Iterable[_Value]], timeout: float = ...) -> Optional[Tuple[_StrType, _StrType]]: ... + @overload + def blpop(self, keys: Union[_Value, Iterable[_Value]], timeout: Literal[0] = ...) -> Tuple[_StrType, _StrType]: ... + @overload + def blpop(self, keys: Union[_Value, Iterable[_Value]], timeout: float) -> Optional[Tuple[_StrType, _StrType]]: ... + @overload + def brpop(self, keys: Union[_Value, Iterable[_Value]], timeout: Literal[0] = ...) -> Tuple[_StrType, _StrType]: ... + @overload + def brpop(self, keys: Union[_Value, Iterable[_Value]], timeout: float) -> Optional[Tuple[_StrType, _StrType]]: ... def brpoplpush(self, src, dst, timeout=...): ... def lindex(self, name: _Key, index: int) -> Optional[_StrType]: ... def linsert(