Skip to content

Commit eb14418

Browse files
committed
refactor: updating typing for xreadgroup / xread / xadd
the typing for these functions are invariant and cannot be used with a typed dict as easily because of that Signed-off-by: James Ward <[email protected]>
1 parent e74cefa commit eb14418

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

valkey/commands/core.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
from valkey.exceptions import ConnectionError, DataError, NoScriptError, ValkeyError
2525
from valkey.typing import (
2626
AbsExpiryT,
27+
AnyEncodableT,
28+
AnyFieldT,
2729
AnyKeyT,
30+
AnyStreamIdT,
2831
BitfieldOffsetT,
2932
ChannelT,
3033
CommandsProtocol,
@@ -3508,7 +3511,7 @@ def xack(self, name: KeyT, groupname: GroupT, *ids: StreamIdT) -> ResponseT:
35083511
def xadd(
35093512
self,
35103513
name: KeyT,
3511-
fields: Dict[FieldT, EncodableT],
3514+
fields: Mapping[AnyFieldT, AnyEncodableT],
35123515
id: StreamIdT = "*",
35133516
maxlen: Union[int, None] = None,
35143517
approximate: bool = True,
@@ -3933,7 +3936,7 @@ def xrange(
39333936

39343937
def xread(
39353938
self,
3936-
streams: Dict[KeyT, StreamIdT],
3939+
streams: Mapping[AnyKeyT, AnyStreamIdT],
39373940
count: Union[int, None] = None,
39383941
block: Union[int, None] = None,
39393942
) -> ResponseT:
@@ -3973,7 +3976,7 @@ def xreadgroup(
39733976
self,
39743977
groupname: str,
39753978
consumername: str,
3976-
streams: Dict[KeyT, StreamIdT],
3979+
streams: Mapping[AnyKeyT, AnyStreamIdT],
39773980
count: Union[int, None] = None,
39783981
block: Union[int, None] = None,
39793982
noack: bool = False,

valkey/typing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
AnyKeyT = TypeVar("AnyKeyT", bytes, str, memoryview)
4848
AnyFieldT = TypeVar("AnyFieldT", bytes, str, memoryview)
4949
AnyChannelT = TypeVar("AnyChannelT", bytes, str, memoryview)
50+
AnyStreamIdT = TypeVar("AnyStreamIdT", int, bytes, str, memoryview)
51+
AnyEncodableT = TypeVar("AnyEncodableT", int, float, bytes, str, memoryview)
5052

5153
ExceptionMappingT = Mapping[str, Union[Type[Exception], Mapping[str, Type[Exception]]]]
5254

0 commit comments

Comments
 (0)