Skip to content

Commit 7370262

Browse files
committed
add type hints
1 parent 9328025 commit 7370262

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

redis/commands/core.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22
import hashlib
33
import time
4+
from typing import List, Optional
45
import warnings
56

67
from redis.exceptions import ConnectionError, DataError, NoScriptError, RedisError
@@ -1926,14 +1927,20 @@ def brpoplpush(self, src, dst, timeout=0):
19261927
timeout = 0
19271928
return self.execute_command("BRPOPLPUSH", src, dst, timeout)
19281929

1929-
def lmpop(self, num_keys, keys, *args, count=1):
1930+
def lmpop(
1931+
self,
1932+
num_keys: int,
1933+
*args: List[str],
1934+
direction: str=None,
1935+
count: Optional[int]=1
1936+
) -> List:
19301937
"""
19311938
Pop ``count`` values (default 1) first non-empty list key from the list
1932-
of provided key names.
1939+
of args provided key names.
19331940
19341941
For more information check https://redis.io/commands/lmpop
19351942
"""
1936-
args = [num_keys] + list_or_args(keys, args)
1943+
args = [num_keys] + list(args) + [direction]
19371944
if count != 1:
19381945
args.extend(["COUNT", count])
19391946

tests/test_commands.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,11 +1478,11 @@ def test_brpoplpush_empty_string(self, r):
14781478
def test_lmpop(self, unstable_r):
14791479
unstable_r.rpush("foo", "1", "2", "3", "4", "5")
14801480
result = [b"foo", [b"1", b"2"]]
1481-
assert unstable_r.lmpop("2", "bar", "foo", "LEFT", count=2) == result
1481+
assert unstable_r.lmpop("2", "bar", "foo", direction="LEFT", count=2) == result
14821482
with pytest.raises(redis.ResponseError):
1483-
unstable_r.lmpop("2", "bar", "foo", count=2)
1483+
unstable_r.lmpop("2", "bar", "foo", direction="up", count=2)
14841484
unstable_r.rpush("bar", "a", "b", "c", "d")
1485-
assert unstable_r.lmpop("2", ["bar", "foo"], "RIGHT") == [b"bar", [b"d"]]
1485+
assert unstable_r.lmpop("2", "bar", "foo", direction="RIGHT") == [b"bar", [b"d"]]
14861486

14871487
def test_lindex(self, r):
14881488
r.rpush("a", "1", "2", "3")

0 commit comments

Comments
 (0)