From 10e40d02a68e5a1c4b4475f2ac5961eb5d9e5635 Mon Sep 17 00:00:00 2001 From: Mikhail Koviazin Date: Thu, 19 Dec 2024 11:37:43 +0100 Subject: [PATCH 1/4] Revert "fixed type hints of hash methods" This reverts commit c006c85e1c4aa2581b6b2a7616759aa5fbd09afc. Signed-off-by: Mikhail Koviazin --- valkey/commands/core.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/valkey/commands/core.py b/valkey/commands/core.py index 5997312f..b1d3e8d9 100644 --- a/valkey/commands/core.py +++ b/valkey/commands/core.py @@ -4944,7 +4944,7 @@ class HashCommands(CommandsProtocol): see: https://valkey.io/topics/data-types-intro#valkey-hashes """ - def hdel(self, name: str, *keys: str) -> int: + def hdel(self, name: str, *keys: str) -> Union[Awaitable[int], int]: """ Delete ``keys`` from hash ``name`` @@ -4952,7 +4952,7 @@ def hdel(self, name: str, *keys: str) -> int: """ return self.execute_command("HDEL", name, *keys) - def hexists(self, name: str, key: str) -> bool: + def hexists(self, name: str, key: str) -> Union[Awaitable[bool], bool]: """ Returns a boolean indicating if ``key`` exists within hash ``name`` @@ -4960,7 +4960,9 @@ def hexists(self, name: str, key: str) -> bool: """ return self.execute_command("HEXISTS", name, key, keys=[name]) - def hget(self, name: str, key: str) -> Optional[bytes]: + def hget( + self, name: str, key: str + ) -> Union[Awaitable[Optional[str]], Optional[str]]: """ Return the value of ``key`` within the hash ``name`` @@ -4968,7 +4970,7 @@ def hget(self, name: str, key: str) -> Optional[bytes]: """ return self.execute_command("HGET", name, key, keys=[name]) - def hgetall(self, name: str) -> dict: + def hgetall(self, name: str) -> Union[Awaitable[dict], dict]: """ Return a Python dict of the hash's name/value pairs @@ -4976,7 +4978,9 @@ def hgetall(self, name: str) -> dict: """ return self.execute_command("HGETALL", name, keys=[name]) - def hincrby(self, name: str, key: str, amount: int = 1) -> int: + def hincrby( + self, name: str, key: str, amount: int = 1 + ) -> Union[Awaitable[int], int]: """ Increment the value of ``key`` in hash ``name`` by ``amount`` @@ -4984,7 +4988,9 @@ def hincrby(self, name: str, key: str, amount: int = 1) -> int: """ return self.execute_command("HINCRBY", name, key, amount) - def hincrbyfloat(self, name: str, key: str, amount: float = 1.0) -> float: + def hincrbyfloat( + self, name: str, key: str, amount: float = 1.0 + ) -> Union[Awaitable[float], float]: """ Increment the value of ``key`` in hash ``name`` by floating ``amount`` @@ -4992,7 +4998,7 @@ def hincrbyfloat(self, name: str, key: str, amount: float = 1.0) -> float: """ return self.execute_command("HINCRBYFLOAT", name, key, amount) - def hkeys(self, name: str) -> List[bytes]: + def hkeys(self, name: str) -> Union[Awaitable[List], List]: """ Return the list of keys within hash ``name`` @@ -5000,7 +5006,7 @@ def hkeys(self, name: str) -> List[bytes]: """ return self.execute_command("HKEYS", name, keys=[name]) - def hlen(self, name: str) -> int: + def hlen(self, name: str) -> Union[Awaitable[int], int]: """ Return the number of elements in hash ``name`` @@ -5015,7 +5021,7 @@ def hset( value: Optional[str] = None, mapping: Optional[dict] = None, items: Optional[list] = None, - ) -> int: + ) -> Union[Awaitable[int], int]: """ Set ``key`` to ``value`` within hash ``name``, ``mapping`` accepts a dict of key/value pairs that will be @@ -5039,7 +5045,7 @@ def hset( return self.execute_command("HSET", name, *pieces) - def hsetnx(self, name: str, key: str, value: str) -> int: + def hsetnx(self, name: str, key: str, value: str) -> Union[Awaitable[bool], bool]: """ Set ``key`` to ``value`` within hash ``name`` if ``key`` does not exist. Returns 1 if HSETNX created a field, otherwise 0. @@ -5048,7 +5054,7 @@ def hsetnx(self, name: str, key: str, value: str) -> int: """ return self.execute_command("HSETNX", name, key, value) - def hmset(self, name: str, mapping: dict) -> bool: + def hmset(self, name: str, mapping: dict) -> Union[Awaitable[str], str]: """ Set key to value within hash ``name`` for each corresponding key and value from the ``mapping`` dict. @@ -5068,7 +5074,7 @@ def hmset(self, name: str, mapping: dict) -> bool: items.extend(pair) return self.execute_command("HMSET", name, *items) - def hmget(self, name: str, keys: List, *args: List) -> List[bytes]: + def hmget(self, name: str, keys: List, *args: List) -> Union[Awaitable[List], List]: """ Returns a list of values ordered identically to ``keys`` @@ -5077,7 +5083,7 @@ def hmget(self, name: str, keys: List, *args: List) -> List[bytes]: args = list_or_args(keys, args) return self.execute_command("HMGET", name, *args, keys=[name]) - def hvals(self, name: str) -> List[bytes]: + def hvals(self, name: str) -> Union[Awaitable[List], List]: """ Return the list of values within hash ``name`` @@ -5085,7 +5091,7 @@ def hvals(self, name: str) -> List[bytes]: """ return self.execute_command("HVALS", name, keys=[name]) - def hstrlen(self, name: str, key: str) -> int: + def hstrlen(self, name: str, key: str) -> Union[Awaitable[int], int]: """ Return the number of bytes stored in the value of ``key`` within hash ``name`` From f4097b305b20ab497b82fc9e6ad9392662256504 Mon Sep 17 00:00:00 2001 From: Mikhail Koviazin Date: Thu, 19 Dec 2024 11:39:19 +0100 Subject: [PATCH 2/4] Revert "fixed type hint of hrandfield method" This reverts commit 1fc6f9b7257ddb489c70ed4b70d7a3ad71b2f2cb. Signed-off-by: Mikhail Koviazin --- valkey/commands/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/valkey/commands/core.py b/valkey/commands/core.py index b1d3e8d9..9fa9ac2b 100644 --- a/valkey/commands/core.py +++ b/valkey/commands/core.py @@ -2153,7 +2153,7 @@ def pttl(self, name: KeyT) -> ResponseT: def hrandfield( self, key: str, count: int = None, withvalues: bool = False - ) -> Union[bytes, List[bytes], None]: + ) -> ResponseT: """ Return a random field from the hash value stored at key. From 2ff7534c420f7030d63f41f3cefacec2d5bb2ff6 Mon Sep 17 00:00:00 2001 From: Mikhail Koviazin Date: Thu, 19 Dec 2024 11:41:04 +0100 Subject: [PATCH 3/4] Revert "update the return type of scan family" This reverts commit 9adb262d53fd2a751f28240271575e434877d4d6. Signed-off-by: Mikhail Koviazin --- valkey/commands/core.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/valkey/commands/core.py b/valkey/commands/core.py index 9fa9ac2b..4da4257e 100644 --- a/valkey/commands/core.py +++ b/valkey/commands/core.py @@ -2995,7 +2995,7 @@ def scan( count: Union[int, None] = None, _type: Union[str, None] = None, **kwargs, - ) -> Tuple[int, List[bytes]]: + ) -> ResponseT: """ Incrementally return lists of key names. Also return a cursor indicating the scan position. @@ -3055,7 +3055,7 @@ def sscan( cursor: int = 0, match: Union[PatternT, None] = None, count: Union[int, None] = None, - ) -> Tuple[int, List[bytes]]: + ) -> ResponseT: """ Incrementally return lists of elements in a set. Also return a cursor indicating the scan position. @@ -3099,7 +3099,7 @@ def hscan( match: Union[PatternT, None] = None, count: Union[int, None] = None, no_values: Union[bool, None] = None, - ) -> Tuple[int, Dict[bytes, bytes]]: + ) -> ResponseT: """ Incrementally return key/value slices in a hash. Also return a cursor indicating the scan position. @@ -3155,7 +3155,7 @@ def zscan( match: Union[PatternT, None] = None, count: Union[int, None] = None, score_cast_func: Union[type, Callable] = float, - ) -> Tuple[int, List[Tuple[bytes, float]]]: + ) -> ResponseT: """ Incrementally return lists of elements in a sorted set. Also return a cursor indicating the scan position. From 837cc9122ee16fc477798cdb89d5c078bc0a82ef Mon Sep 17 00:00:00 2001 From: Mikhail Koviazin Date: Thu, 19 Dec 2024 12:00:47 +0100 Subject: [PATCH 4/4] commands: remove unused import Signed-off-by: Mikhail Koviazin --- valkey/commands/core.py | 1 - 1 file changed, 1 deletion(-) diff --git a/valkey/commands/core.py b/valkey/commands/core.py index 4da4257e..298ff3cd 100644 --- a/valkey/commands/core.py +++ b/valkey/commands/core.py @@ -8,7 +8,6 @@ AsyncIterator, Awaitable, Callable, - Dict, Iterable, Iterator, List,