From 3592e04cb996c1a49aeac09e8520b0db42529c05 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Mon, 19 Sep 2022 12:59:19 +0300 Subject: [PATCH] Remove `deprecated` dependency No need for an external library just for 5 annotations. --- CHANGES | 1 + redis/commands/bf/commands.py | 8 ++++---- redis/commands/json/commands.py | 31 +++++++++++++++++++------------ redis/utils.py | 11 +++++++++++ requirements.txt | 1 - setup.py | 1 - 6 files changed, 35 insertions(+), 18 deletions(-) diff --git a/CHANGES b/CHANGES index 47600cf0d0..1fb78cd7ee 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,7 @@ * Fix reusing the old nodes' connections when cluster topology refresh is being done * Fix RedisCluster to immediately raise AuthenticationError without a retry * ClusterPipeline Doesn't Handle ConnectionError for Dead Hosts (#2225) + * The `deprecated` library is no longer a dependency * 4.1.3 (Feb 8, 2022) * Fix flushdb and flushall (#1926) diff --git a/redis/commands/bf/commands.py b/redis/commands/bf/commands.py index 71c9c8a593..41d5fd663b 100644 --- a/redis/commands/bf/commands.py +++ b/redis/commands/bf/commands.py @@ -1,8 +1,6 @@ -from deprecated import deprecated - from redis.client import NEVER_DECODE from redis.exceptions import ModuleError -from redis.utils import HIREDIS_AVAILABLE +from redis.utils import HIREDIS_AVAILABLE, warn_deprecated BF_RESERVE = "BF.RESERVE" BF_ADD = "BF.ADD" @@ -327,12 +325,14 @@ def query(self, key, *items): """ # noqa return self.execute_command(TOPK_QUERY, key, *items) - @deprecated(version="4.4.0", reason="deprecated since redisbloom 2.4.0") def count(self, key, *items): """ Return count for one `item` or more from `key`. For more information see `TOPK.COUNT `_. """ # noqa + warn_deprecated( + name="count", reason="deprecated since redisbloom 2.4.0", version="4.4.0" + ) return self.execute_command(TOPK_COUNT, key, *items) def list(self, key, withcount=False): diff --git a/redis/commands/json/commands.py b/redis/commands/json/commands.py index 9391c2a2c1..21c469e895 100644 --- a/redis/commands/json/commands.py +++ b/redis/commands/json/commands.py @@ -2,9 +2,8 @@ from json import JSONDecodeError, loads from typing import Dict, List, Optional, Union -from deprecated import deprecated - from redis.exceptions import DataError +from redis.utils import warn_deprecated from ._util import JsonType from .decoders import decode_dict_keys @@ -137,13 +136,15 @@ def numincrby(self, name: str, path: str, number: int) -> str: "JSON.NUMINCRBY", name, str(path), self._encode(number) ) - @deprecated(version="4.0.0", reason="deprecated since redisjson 1.0.0") def nummultby(self, name: str, path: str, number: int) -> str: """Multiply the numeric (integer or floating point) JSON value under ``path`` at key ``name`` with the provided ``number``. For more information see `JSON.NUMMULTBY `_. """ # noqa + warn_deprecated( + name="nummultby", reason="deprecated since redisjson 1.0.0", version="4.0.0" + ) return self.execute_command( "JSON.NUMMULTBY", name, str(path), self._encode(number) ) @@ -368,20 +369,26 @@ def debug( pieces.append(str(path)) return self.execute_command("JSON.DEBUG", *pieces) - @deprecated( - version="4.0.0", reason="redisjson-py supported this, call get directly." - ) def jsonget(self, *args, **kwargs): + warn_deprecated( + name="jsonget", + reason="redisjson-py supported this, call get directly.", + version="4.0.0", + ) return self.get(*args, **kwargs) - @deprecated( - version="4.0.0", reason="redisjson-py supported this, call get directly." - ) def jsonmget(self, *args, **kwargs): + warn_deprecated( + name="jsonmget", + reason="redisjson-py supported this, call get directly.", + version="4.0.0", + ) return self.mget(*args, **kwargs) - @deprecated( - version="4.0.0", reason="redisjson-py supported this, call get directly." - ) def jsonset(self, *args, **kwargs): + warn_deprecated( + name="jsonset", + reason="redisjson-py supported this, call get directly.", + version="4.0.0", + ) return self.set(*args, **kwargs) diff --git a/redis/utils.py b/redis/utils.py index 0c34e1eef8..6763431983 100644 --- a/redis/utils.py +++ b/redis/utils.py @@ -79,3 +79,14 @@ def merge_result(command, res): result.add(value) return list(result) + + +def warn_deprecated(name, reason="", version=""): + import warnings + + msg = f"Call to deprecated {name}." + if reason: + msg += f" ({reason})" + if version: + msg += f" -- Deprecated since version {version}." + warnings.warn(msg, category=DeprecationWarning, stacklevel=2) diff --git a/requirements.txt b/requirements.txt index c40eca70e0..e2c33999e3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ async-timeout>=4.0.2 -deprecated>=1.2.3 packaging>=20.4 typing-extensions; python_version<"3.8" diff --git a/setup.py b/setup.py index fb6d32a31d..20d756e6db 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,6 @@ author_email="oss@redis.com", python_requires=">=3.7", install_requires=[ - "deprecated>=1.2.3", "packaging>=20.4", 'importlib-metadata >= 1.0; python_version < "3.8"', 'typing-extensions; python_version<"3.8"',