Skip to content

Commit f5a17d4

Browse files
committed
Docs: Resolve "more than one target for cross-reference 'Redis'" warnings
When Sphinx runs, `TYPE_CHECKING` is not enabled, so the differentiating sync/async `Redis` imports don't happen, and Sphinx appears to be unable to infer which class `"Redis"` should cross-reference.
1 parent aeddcc8 commit f5a17d4

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

redis/commands/core.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
from .helpers import list_or_args
4747

4848
if TYPE_CHECKING:
49-
from redis.asyncio.client import Redis as AsyncRedis
50-
from redis.client import Redis
49+
import redis.asyncio.client
50+
import redis.client
5151

5252

5353
class ACLCommands(CommandsProtocol):
@@ -1442,7 +1442,7 @@ class BitFieldOperation:
14421442

14431443
def __init__(
14441444
self,
1445-
client: Union["Redis", "AsyncRedis"],
1445+
client: Union["redis.client.Redis", "redis.asyncio.client.Redis"],
14461446
key: str,
14471447
default_overflow: Union[str, None] = None,
14481448
):
@@ -1586,7 +1586,7 @@ def bitcount(
15861586
return self.execute_command("BITCOUNT", *params, keys=[key])
15871587

15881588
def bitfield(
1589-
self: Union["Redis", "AsyncRedis"],
1589+
self: Union["redis.client.Redis", "redis.asyncio.client.Redis"],
15901590
key: KeyT,
15911591
default_overflow: Union[str, None] = None,
15921592
) -> BitFieldOperation:
@@ -1599,7 +1599,7 @@ def bitfield(
15991599
return BitFieldOperation(self, key, default_overflow=default_overflow)
16001600

16011601
def bitfield_ro(
1602-
self: Union["Redis", "AsyncRedis"],
1602+
self: Union["redis.client.Redis", "redis.asyncio.client.Redis"],
16031603
key: KeyT,
16041604
encoding: str,
16051605
offset: BitfieldOffsetT,
@@ -5467,7 +5467,7 @@ class Script:
54675467
An executable Lua script object returned by ``register_script``
54685468
"""
54695469

5470-
def __init__(self, registered_client: "Redis", script: ScriptTextT):
5470+
def __init__(self, registered_client: "redis.client.Redis", script: ScriptTextT):
54715471
self.registered_client = registered_client
54725472
self.script = script
54735473
# Precalculate and store the SHA1 hex digest of the script.
@@ -5487,7 +5487,7 @@ def __call__(
54875487
self,
54885488
keys: Union[Sequence[KeyT], None] = None,
54895489
args: Union[Iterable[EncodableT], None] = None,
5490-
client: Union["Redis", None] = None,
5490+
client: Union["redis.client.Redis", None] = None,
54915491
):
54925492
"""Execute the script, passing any required ``args``"""
54935493
keys = keys or []
@@ -5516,7 +5516,11 @@ class AsyncScript:
55165516
An executable Lua script object returned by ``register_script``
55175517
"""
55185518

5519-
def __init__(self, registered_client: "AsyncRedis", script: ScriptTextT):
5519+
def __init__(
5520+
self,
5521+
registered_client: "redis.asyncio.client.Redis",
5522+
script: ScriptTextT,
5523+
):
55205524
self.registered_client = registered_client
55215525
self.script = script
55225526
# Precalculate and store the SHA1 hex digest of the script.
@@ -5536,7 +5540,7 @@ async def __call__(
55365540
self,
55375541
keys: Union[Sequence[KeyT], None] = None,
55385542
args: Union[Iterable[EncodableT], None] = None,
5539-
client: Union["AsyncRedis", None] = None,
5543+
client: Union["redis.asyncio.client.Redis", None] = None,
55405544
):
55415545
"""Execute the script, passing any required ``args``"""
55425546
keys = keys or []
@@ -5761,7 +5765,7 @@ def script_load(self, script: ScriptTextT) -> ResponseT:
57615765
"""
57625766
return self.execute_command("SCRIPT LOAD", script)
57635767

5764-
def register_script(self: "Redis", script: ScriptTextT) -> Script:
5768+
def register_script(self: "redis.client.Redis", script: ScriptTextT) -> Script:
57655769
"""
57665770
Register a Lua ``script`` specifying the ``keys`` it will touch.
57675771
Returns a Script object that is callable and hides the complexity of
@@ -5775,7 +5779,10 @@ class AsyncScriptCommands(ScriptCommands):
57755779
async def script_debug(self, *args) -> None:
57765780
return super().script_debug()
57775781

5778-
def register_script(self: "AsyncRedis", script: ScriptTextT) -> AsyncScript:
5782+
def register_script(
5783+
self: "redis.asyncio.client.Redis",
5784+
script: ScriptTextT,
5785+
) -> AsyncScript:
57795786
"""
57805787
Register a Lua ``script`` specifying the ``keys`` it will touch.
57815788
Returns a Script object that is callable and hides the complexity of

0 commit comments

Comments
 (0)