Skip to content

Commit 08b0dd9

Browse files
committed
updated type hinting for zrange and zrangestore
Fixes #252 and closes #253 Signed-off-by: Mikhail Koviazin <github@mkmk.aleeas.com>
1 parent 2aa9c1d commit 08b0dd9

File tree

2 files changed

+162
-14
lines changed

2 files changed

+162
-14
lines changed

valkey/commands/core.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4432,8 +4432,8 @@ def _zrange(
44324432
command,
44334433
dest: Union[KeyT, None],
44344434
name: KeyT,
4435-
start: int,
4436-
end: int,
4435+
start: EncodableT,
4436+
end: EncodableT,
44374437
desc: bool = False,
44384438
byscore: bool = False,
44394439
bylex: bool = False,
@@ -4471,8 +4471,8 @@ def _zrange(
44714471
def zrange(
44724472
self,
44734473
name: KeyT,
4474-
start: int,
4475-
end: int,
4474+
start: EncodableT,
4475+
end: EncodableT,
44764476
desc: bool = False,
44774477
withscores: bool = False,
44784478
score_cast_func: Union[type, Callable] = float,
@@ -4504,8 +4504,7 @@ def zrange(
45044504
Valid ``start`` and ``end`` must start with ( or [, in order to specify
45054505
whether the range interval is exclusive or inclusive, respectively.
45064506
4507-
``offset`` and ``num`` are specified, then return a slice of the range.
4508-
Can't be provided when using ``bylex``.
4507+
If ``offset`` and ``num`` are specified, return a slice of the range.
45094508
45104509
For more information see https://valkey.io/commands/zrange
45114510
"""
@@ -4561,8 +4560,8 @@ def zrangestore(
45614560
self,
45624561
dest: KeyT,
45634562
name: KeyT,
4564-
start: int,
4565-
end: int,
4563+
start: EncodableT,
4564+
end: EncodableT,
45664565
byscore: bool = False,
45674566
bylex: bool = False,
45684567
desc: bool = False,
@@ -4587,8 +4586,7 @@ def zrangestore(
45874586
``desc`` a boolean indicating whether to sort the results in reversed
45884587
order.
45894588
4590-
``offset`` and ``num`` are specified, then return a slice of the range.
4591-
Can't be provided when using ``bylex``.
4589+
If ``offset`` and ``num`` are specified, return a slice of the range.
45924590
45934591
For more information see https://valkey.io/commands/zrangestore
45944592
"""

valkey/commands/core.pyi

Lines changed: 154 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,12 +1986,87 @@ class SortedSetCommands(CommandsMixin, Generic[_StrType]):
19861986
max: bool | None = False,
19871987
count: int = 1,
19881988
) -> list[Any] | None: ...
1989+
@overload
19891990
def zrange(
19901991
self,
19911992
name: _Key,
19921993
start: int,
19931994
end: int,
19941995
desc: bool = False,
1996+
withscores: Literal[False] = False,
1997+
score_cast_func: type | Callable = ...,
1998+
byscore: Literal[False] = False,
1999+
bylex: Literal[False] = False,
2000+
offset: int | None = None,
2001+
num: int | None = None,
2002+
) -> list[_StrType]: ...
2003+
@overload
2004+
def zrange(
2005+
self,
2006+
name: _Key,
2007+
start: int,
2008+
end: int,
2009+
desc: bool = False,
2010+
*,
2011+
withscores: Literal[True],
2012+
score_cast_func: type | Callable = ...,
2013+
byscore: Literal[False] = False,
2014+
bylex: Literal[False] = False,
2015+
offset: int | None = None,
2016+
num: int | None = None,
2017+
) -> list[_ZSetScorePairT]: ...
2018+
@overload
2019+
def zrange(
2020+
self,
2021+
name: _Key,
2022+
start: ZScoreBoundT,
2023+
end: ZScoreBoundT,
2024+
desc: bool = False,
2025+
withscores: Literal[False] = False,
2026+
score_cast_func: type | Callable = ...,
2027+
*,
2028+
byscore: Literal[True],
2029+
bylex: Literal[False] = False,
2030+
offset: int | None = None,
2031+
num: int | None = None,
2032+
) -> list[_StrType]: ...
2033+
@overload
2034+
def zrange(
2035+
self,
2036+
name: _Key,
2037+
start: ZScoreBoundT,
2038+
end: ZScoreBoundT,
2039+
desc: bool = False,
2040+
*,
2041+
withscores: Literal[True],
2042+
score_cast_func: type | Callable = ...,
2043+
byscore: Literal[True],
2044+
bylex: Literal[False] = False,
2045+
offset: int | None = None,
2046+
num: int | None = None,
2047+
) -> list[_ZSetScorePairT]: ...
2048+
@overload
2049+
def zrange(
2050+
self,
2051+
name: _Key,
2052+
start: _Value,
2053+
end: _Value,
2054+
desc: bool = False,
2055+
withscores: Literal[False] = False,
2056+
score_cast_func: type | Callable = ...,
2057+
byscore: Literal[False] = False,
2058+
*,
2059+
bylex: Literal[True],
2060+
offset: int | None = None,
2061+
num: int | None = None,
2062+
) -> list[_StrType]: ...
2063+
@overload
2064+
def zrange(
2065+
self,
2066+
name: _Key,
2067+
start: _Value,
2068+
end: _Value,
2069+
desc: bool = False,
19952070
withscores: bool = False,
19962071
score_cast_func: type | Callable = ...,
19972072
byscore: bool = False,
@@ -2030,8 +2105,8 @@ class SortedSetCommands(CommandsMixin, Generic[_StrType]):
20302105
self,
20312106
dest: _Key,
20322107
name: _Key,
2033-
start: int,
2034-
end: int,
2108+
start: _Value,
2109+
end: _Value,
20352110
byscore: bool = False,
20362111
bylex: bool = False,
20372112
desc: bool = False,
@@ -2271,12 +2346,87 @@ class AsyncSortedSetCommands(CommandsMixin, Generic[_StrType]):
22712346
max: bool | None = False,
22722347
count: int = 1,
22732348
) -> list[Any] | None: ...
2349+
@overload
22742350
async def zrange(
22752351
self,
22762352
name: _Key,
22772353
start: int,
22782354
end: int,
22792355
desc: bool = False,
2356+
withscores: Literal[False] = False,
2357+
score_cast_func: type | Callable = ...,
2358+
byscore: Literal[False] = False,
2359+
bylex: Literal[False] = False,
2360+
offset: int | None = None,
2361+
num: int | None = None,
2362+
) -> list[_StrType]: ...
2363+
@overload
2364+
async def zrange(
2365+
self,
2366+
name: _Key,
2367+
start: int,
2368+
end: int,
2369+
desc: bool = False,
2370+
*,
2371+
withscores: Literal[True],
2372+
score_cast_func: type | Callable = ...,
2373+
byscore: Literal[False] = False,
2374+
bylex: Literal[False] = False,
2375+
offset: int | None = None,
2376+
num: int | None = None,
2377+
) -> list[_ZSetScorePairT]: ...
2378+
@overload
2379+
async def zrange(
2380+
self,
2381+
name: _Key,
2382+
start: ZScoreBoundT,
2383+
end: ZScoreBoundT,
2384+
desc: bool = False,
2385+
withscores: Literal[False] = False,
2386+
score_cast_func: type | Callable = ...,
2387+
*,
2388+
byscore: Literal[True],
2389+
bylex: Literal[False] = False,
2390+
offset: int | None = None,
2391+
num: int | None = None,
2392+
) -> list[_StrType]: ...
2393+
@overload
2394+
async def zrange(
2395+
self,
2396+
name: _Key,
2397+
start: ZScoreBoundT,
2398+
end: ZScoreBoundT,
2399+
desc: bool = False,
2400+
*,
2401+
withscores: Literal[True],
2402+
score_cast_func: type | Callable = ...,
2403+
byscore: Literal[True],
2404+
bylex: Literal[False] = False,
2405+
offset: int | None = None,
2406+
num: int | None = None,
2407+
) -> list[_ZSetScorePairT]: ...
2408+
@overload
2409+
async def zrange(
2410+
self,
2411+
name: _Key,
2412+
start: _Value,
2413+
end: _Value,
2414+
desc: bool = False,
2415+
withscores: Literal[False] = False,
2416+
score_cast_func: type | Callable = ...,
2417+
byscore: Literal[False] = False,
2418+
*,
2419+
bylex: Literal[True],
2420+
offset: int | None = None,
2421+
num: int | None = None,
2422+
) -> list[_StrType]: ...
2423+
@overload
2424+
async def zrange(
2425+
self,
2426+
name: _Key,
2427+
start: _Value,
2428+
end: _Value,
2429+
desc: bool = False,
22802430
withscores: bool = False,
22812431
score_cast_func: type | Callable = ...,
22822432
byscore: bool = False,
@@ -2315,8 +2465,8 @@ class AsyncSortedSetCommands(CommandsMixin, Generic[_StrType]):
23152465
self,
23162466
dest: _Key,
23172467
name: _Key,
2318-
start: int,
2319-
end: int,
2468+
start: _Value,
2469+
end: _Value,
23202470
byscore: bool = False,
23212471
bylex: bool = False,
23222472
desc: bool = False,

0 commit comments

Comments
 (0)