Skip to content

Commit

Permalink
refactor: updating typing for xreadgroup / xread / xadd
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
imnotjames committed Dec 2, 2024
1 parent c490780 commit 5f0bf34
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions valkey/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
AsyncIterator,
Awaitable,
Callable,
Dict,
Iterable,
Iterator,
List,
Expand All @@ -25,6 +24,8 @@
from valkey.typing import (
AbsExpiryT,
AnyKeyT,
AnyFieldT,
AnyStreamIdT,
BitfieldOffsetT,
ChannelT,
CommandsProtocol,
Expand Down Expand Up @@ -3508,7 +3509,7 @@ def xack(self, name: KeyT, groupname: GroupT, *ids: StreamIdT) -> ResponseT:
def xadd(
self,
name: KeyT,
fields: Dict[FieldT, EncodableT],
fields: Mapping[AnyFieldT, EncodableT],
id: StreamIdT = "*",
maxlen: Union[int, None] = None,
approximate: bool = True,
Expand Down Expand Up @@ -3933,7 +3934,7 @@ def xrange(

def xread(
self,
streams: Dict[KeyT, StreamIdT],
streams: Mapping[AnyKeyT, AnyStreamIdT],
count: Union[int, None] = None,
block: Union[int, None] = None,
) -> ResponseT:
Expand Down Expand Up @@ -3973,7 +3974,7 @@ def xreadgroup(
self,
groupname: str,
consumername: str,
streams: Dict[KeyT, StreamIdT],
streams: Mapping[AnyKeyT, AnyStreamIdT],
count: Union[int, None] = None,
block: Union[int, None] = None,
noack: bool = False,
Expand Down
1 change: 1 addition & 0 deletions valkey/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
AnyKeyT = TypeVar("AnyKeyT", bytes, str, memoryview)
AnyFieldT = TypeVar("AnyFieldT", bytes, str, memoryview)
AnyChannelT = TypeVar("AnyChannelT", bytes, str, memoryview)
AnyStreamIdT = TypeVar("AnyStreamIdT", int, bytes, str, memoryview)

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

Expand Down

0 comments on commit 5f0bf34

Please sign in to comment.