Skip to content

Commit abd08b0

Browse files
authored
Type hints improvements - fixing static code analyses issues related to combined sync and async return types(vectorsets + commands in core.py) (#3991)
* Type hints refactoring analyses * POC * Applying review comments. Updating the type hints pattern - adopting more modern syntax. VectorSets commands are fully covered * Updating command changes analyses and progress status * Fixing get/set args type hints to follow PEP 604 * Add agent instruction * Updating analyses with more accurate data. Adding overloads for three batches * Adding batch 4 * Adding batch 5 * Applying review comments * Adding batch 6 * Adding batch 7 * Fixing linters + LSP violation * Adding batch 8 * Adding batch 9 * Adding batch 10 * Adding batch 11 and 12 - final ones for core.py * Fixing misplaced overloads
1 parent a3bcb11 commit abd08b0

16 files changed

Lines changed: 6760 additions & 617 deletions

.agent/sync_async_type_hints_overload_guide.md

Lines changed: 812 additions & 0 deletions
Large diffs are not rendered by default.

redis/asyncio/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Dict,
1414
Iterable,
1515
List,
16+
Literal,
1617
Mapping,
1718
MutableMapping,
1819
Optional,
@@ -129,6 +130,9 @@ class Redis(
129130
Connection object to talk to redis.
130131
"""
131132

133+
# Type discrimination marker for @overload self-type pattern
134+
_is_async_client: Literal[True] = True
135+
132136
response_callbacks: MutableMapping[Union[str, bytes], ResponseCallbackT]
133137

134138
@classmethod

redis/asyncio/cluster.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
Dict,
1717
Generator,
1818
List,
19+
Literal,
1920
Mapping,
2021
Optional,
2122
Set,
@@ -238,6 +239,9 @@ def from_url(cls, url: str, **kwargs: Any) -> "RedisCluster":
238239
kwargs["ssl"] = True
239240
return cls(**kwargs)
240241

242+
# Type discrimination marker for @overload self-type pattern
243+
_is_async_client: Literal[True] = True
244+
241245
__slots__ = (
242246
"_initialize",
243247
"_lock",
@@ -1976,7 +1980,14 @@ class ClusterPipeline(AbstractRedis, AbstractRedisCluster, AsyncRedisClusterComm
19761980
| Existing :class:`~.RedisCluster` client
19771981
"""
19781982

1979-
__slots__ = ("cluster_client", "_transaction", "_execution_strategy")
1983+
__slots__ = (
1984+
"cluster_client",
1985+
"_transaction",
1986+
"_execution_strategy",
1987+
)
1988+
1989+
# Type discrimination marker for @overload self-type pattern
1990+
_is_async_client: Literal[True] = True
19801991

19811992
def __init__(
19821993
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/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
Callable,
1111
Dict,
1212
List,
13+
Literal,
1314
Mapping,
1415
Optional,
1516
Set,
@@ -151,6 +152,9 @@ class Redis(RedisModuleCommands, CoreCommands, SentinelCommands):
151152
It is not safe to pass PubSub or Pipeline objects between threads.
152153
"""
153154

155+
# Type discrimination marker for @overload self-type pattern
156+
_is_async_client: Literal[False] = False
157+
154158
@classmethod
155159
def from_url(cls, url: str, **kwargs) -> "Redis":
156160
"""

redis/cluster.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,9 @@ def replace_default_node(self, target_node: "ClusterNode" = None) -> None:
554554
class RedisCluster(
555555
AbstractRedisCluster, MaintNotificationsAbstractRedisCluster, RedisClusterCommands
556556
):
557+
# Type discrimination marker for @overload self-type pattern
558+
_is_async_client: Literal[False] = False
559+
557560
@classmethod
558561
def from_url(cls, url: str, **kwargs: Any) -> "RedisCluster":
559562
"""

0 commit comments

Comments
 (0)