Skip to content

Commit 40b6eb3

Browse files
committed
Applying review comments. Updating the type hints pattern - adopting more modern syntax. VectorSets commands are fully covered
1 parent 18e2863 commit 40b6eb3

7 files changed

Lines changed: 237 additions & 91 deletions

File tree

redis/asyncio/cluster.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1980,7 +1980,14 @@ class ClusterPipeline(AbstractRedis, AbstractRedisCluster, AsyncRedisClusterComm
19801980
| Existing :class:`~.RedisCluster` client
19811981
"""
19821982

1983-
__slots__ = ("cluster_client", "_transaction", "_execution_strategy")
1983+
__slots__ = (
1984+
"cluster_client",
1985+
"_transaction",
1986+
"_execution_strategy",
1987+
"_is_async_client",
1988+
)
1989+
1990+
_is_async_client: Literal[True] = True
19841991

19851992
def __init__(
19861993
self, client: RedisCluster, transaction: Optional[bool] = None

redis/asyncio/multidb/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import asyncio
22
import logging
3-
from typing import Any, Awaitable, Callable, List, Optional, Union
3+
from typing import Any, Awaitable, Callable, List, Literal, Optional, Union
44

55
from redis.asyncio.client import PubSubHandler
66
from redis.asyncio.multidb.command_executor import DefaultCommandExecutor
@@ -441,6 +441,8 @@ class Pipeline(AsyncRedisModuleCommands, AsyncCoreCommands):
441441
Pipeline implementation for multiple logical Redis databases.
442442
"""
443443

444+
_is_async_client: Literal[True] = True
445+
444446
def __init__(self, client: MultiDBClient):
445447
self._command_stack = []
446448
self._client = client

redis/commands/core.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,16 +2067,14 @@ def digest(self, name: KeyT) -> Union[str, bytes, None]:
20672067
# Bulk string response is already handled (bytes/str based on decode_responses)
20682068
return self.execute_command("DIGEST", name)
20692069

2070-
# --- @overload pattern for get() ---
2071-
# Sync client returns bytes | None directly
20722070
@overload
2073-
def get(self: SyncClientProtocol, name: KeyT) -> Optional[bytes]: ...
2071+
def get(self: SyncClientProtocol, name: KeyT) -> bytes | str | None: ...
20742072

20752073
# Async client returns Awaitable[bytes | None]
20762074
@overload
2077-
def get(self: AsyncClientProtocol, name: KeyT) -> Awaitable[Optional[bytes]]: ...
2075+
def get(self: AsyncClientProtocol, name: KeyT) -> Awaitable[bytes | str | None]: ...
20782076

2079-
def get(self, name: KeyT) -> ResponseT:
2077+
def get(self, name: KeyT) -> (bytes | str | None) | Awaitable[bytes | str | None]:
20802078
"""
20812079
Return the value at key ``name``, or None if the key doesn't exist
20822080
@@ -2566,8 +2564,6 @@ def restore(
25662564

25672565
return self.execute_command("RESTORE", *params)
25682566

2569-
# --- @overload pattern for set() ---
2570-
# Sync client returns bool | None directly
25712567
@overload
25722568
def set(
25732569
self: SyncClientProtocol,
@@ -2585,7 +2581,7 @@ def set(
25852581
ifne: Optional[Union[bytes, str]] = ...,
25862582
ifdeq: Optional[str] = ...,
25872583
ifdne: Optional[str] = ...,
2588-
) -> Optional[bool]: ...
2584+
) -> bool | str | bytes | None: ...
25892585

25902586
# Async client returns Awaitable[bool | None]
25912587
@overload
@@ -2605,7 +2601,7 @@ def set(
26052601
ifne: Optional[Union[bytes, str]] = ...,
26062602
ifdeq: Optional[str] = ...,
26072603
ifdne: Optional[str] = ...,
2608-
) -> Awaitable[Optional[bool]]: ...
2604+
) -> Awaitable[bool | str | bytes | None]: ...
26092605

26102606
@experimental_args(["ifeq", "ifne", "ifdeq", "ifdne"])
26112607
def set(
@@ -2624,7 +2620,7 @@ def set(
26242620
ifne: Optional[Union[bytes, str]] = None,
26252621
ifdeq: Optional[str] = None, # hex digest of current value
26262622
ifdne: Optional[str] = None, # hex digest of current value
2627-
) -> ResponseT:
2623+
) -> (bool | str | bytes | None) | Awaitable[bool | str | bytes | None]:
26282624
"""
26292625
Set the value at key ``name`` to ``value``
26302626

redis/commands/search/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Literal
2+
13
from redis.client import Pipeline as RedisPipeline
24

35
from ...asyncio.client import Pipeline as AsyncioPipeline
@@ -186,6 +188,10 @@ def pipeline(self, transaction=True, shard_hint=None):
186188
class Pipeline(SearchCommands, RedisPipeline):
187189
"""Pipeline for the module."""
188190

191+
_is_async_client: Literal[False] = False
192+
189193

190194
class AsyncPipeline(AsyncSearchCommands, AsyncioPipeline, Pipeline):
191195
"""AsyncPipeline for the module."""
196+
197+
_is_async_client: Literal[True] = True

0 commit comments

Comments
 (0)