From 7ed8c5b8fb670c44e5331d7e1535abdd7d18e0ea Mon Sep 17 00:00:00 2001 From: J Richards Date: Fri, 24 Oct 2025 15:08:49 -0700 Subject: [PATCH] Fix: type hints on from_url --- redis/asyncio/client.py | 2 +- redis/asyncio/utils.py | 4 ++-- redis/cluster.py | 2 +- redis/utils.py | 7 +++++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/redis/asyncio/client.py b/redis/asyncio/client.py index 1cc0365a7b..49b66ccd26 100644 --- a/redis/asyncio/client.py +++ b/redis/asyncio/client.py @@ -131,7 +131,7 @@ def from_url( single_connection_client: bool = False, auto_close_connection_pool: Optional[bool] = None, **kwargs, - ): + ) -> "Redis": """ Return a Redis client object configured from the given URL diff --git a/redis/asyncio/utils.py b/redis/asyncio/utils.py index fa014514ec..f7d5121f8c 100644 --- a/redis/asyncio/utils.py +++ b/redis/asyncio/utils.py @@ -1,10 +1,10 @@ -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any if TYPE_CHECKING: from redis.asyncio.client import Pipeline, Redis -def from_url(url, **kwargs): +def from_url(url: str, **kwargs: Any) -> "Redis": """ Returns an active Redis client generated from the given database URL. diff --git a/redis/cluster.py b/redis/cluster.py index c238c171be..99fbdca2da 100644 --- a/redis/cluster.py +++ b/redis/cluster.py @@ -460,7 +460,7 @@ def replace_default_node(self, target_node: "ClusterNode" = None) -> None: class RedisCluster(AbstractRedisCluster, RedisClusterCommands): @classmethod - def from_url(cls, url, **kwargs): + def from_url(cls, url: str, **kwargs: Any) -> "RedisCluster": """ Return a Redis client object configured from the given URL diff --git a/redis/utils.py b/redis/utils.py index 66c1480a9b..129aadc3e7 100644 --- a/redis/utils.py +++ b/redis/utils.py @@ -5,11 +5,14 @@ from collections.abc import Callable from contextlib import contextmanager from functools import wraps -from typing import Any, Dict, List, Mapping, Optional, TypeVar, Union +from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Optional, TypeVar, Union from redis.exceptions import DataError from redis.typing import AbsExpiryT, EncodableT, ExpiryT +if TYPE_CHECKING: + from redis.client import Redis + try: import hiredis # noqa @@ -40,7 +43,7 @@ from importlib import metadata -def from_url(url, **kwargs): +def from_url(url: str, **kwargs: Any) -> "Redis": """ Returns an active Redis client generated from the given database URL.