Skip to content

Commit 842634e

Browse files
authored
Remove deprecated dependency (#2386)
No need for an external library just for 5 annotations.
1 parent 9cf8e02 commit 842634e

File tree

7 files changed

+39
-16
lines changed

7 files changed

+39
-16
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Fix RedisCluster to immediately raise AuthenticationError without a retry
2323
* ClusterPipeline Doesn't Handle ConnectionError for Dead Hosts (#2225)
2424
* Remove compatibility code for old versions of Hiredis, drop Packaging dependency
25+
* The `deprecated` library is no longer a dependency
2526

2627
* 4.1.3 (Feb 8, 2022)
2728
* Fix flushdb and flushall (#1926)

redis/commands/bf/commands.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
from deprecated import deprecated
2-
31
from redis.client import NEVER_DECODE
42
from redis.exceptions import ModuleError
5-
from redis.utils import HIREDIS_AVAILABLE
3+
from redis.utils import HIREDIS_AVAILABLE, deprecated_function
64

75
BF_RESERVE = "BF.RESERVE"
86
BF_ADD = "BF.ADD"
@@ -327,7 +325,7 @@ def query(self, key, *items):
327325
""" # noqa
328326
return self.execute_command(TOPK_QUERY, key, *items)
329327

330-
@deprecated(version="4.4.0", reason="deprecated since redisbloom 2.4.0")
328+
@deprecated_function(version="4.4.0", reason="deprecated since redisbloom 2.4.0")
331329
def count(self, key, *items):
332330
"""
333331
Return count for one `item` or more from `key`.

redis/commands/json/commands.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
from json import JSONDecodeError, loads
33
from typing import Dict, List, Optional, Union
44

5-
from deprecated import deprecated
6-
75
from redis.exceptions import DataError
6+
from redis.utils import deprecated_function
87

98
from ._util import JsonType
109
from .decoders import decode_dict_keys
@@ -137,7 +136,7 @@ def numincrby(self, name: str, path: str, number: int) -> str:
137136
"JSON.NUMINCRBY", name, str(path), self._encode(number)
138137
)
139138

140-
@deprecated(version="4.0.0", reason="deprecated since redisjson 1.0.0")
139+
@deprecated_function(version="4.0.0", reason="deprecated since redisjson 1.0.0")
141140
def nummultby(self, name: str, path: str, number: int) -> str:
142141
"""Multiply the numeric (integer or floating point) JSON value under
143142
``path`` at key ``name`` with the provided ``number``.
@@ -368,19 +367,19 @@ def debug(
368367
pieces.append(str(path))
369368
return self.execute_command("JSON.DEBUG", *pieces)
370369

371-
@deprecated(
370+
@deprecated_function(
372371
version="4.0.0", reason="redisjson-py supported this, call get directly."
373372
)
374373
def jsonget(self, *args, **kwargs):
375374
return self.get(*args, **kwargs)
376375

377-
@deprecated(
376+
@deprecated_function(
378377
version="4.0.0", reason="redisjson-py supported this, call get directly."
379378
)
380379
def jsonmget(self, *args, **kwargs):
381380
return self.mget(*args, **kwargs)
382381

383-
@deprecated(
382+
@deprecated_function(
384383
version="4.0.0", reason="redisjson-py supported this, call get directly."
385384
)
386385
def jsonset(self, *args, **kwargs):

redis/commands/search/commands.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
import time
33
from typing import Dict, Optional, Union
44

5-
from deprecated import deprecated
6-
75
from redis.client import Pipeline
6+
from redis.utils import deprecated_function
87

98
from ..helpers import parse_to_dict
109
from ._util import to_string
@@ -238,7 +237,7 @@ def _add_document_hash(
238237

239238
return self.execute_command(*args)
240239

241-
@deprecated(
240+
@deprecated_function(
242241
version="2.0.0", reason="deprecated since redisearch 2.0, call hset instead"
243242
)
244243
def add_document(
@@ -294,7 +293,7 @@ def add_document(
294293
**fields,
295294
)
296295

297-
@deprecated(
296+
@deprecated_function(
298297
version="2.0.0", reason="deprecated since redisearch 2.0, call hset instead"
299298
)
300299
def add_document_hash(self, doc_id, score=1.0, language=None, replace=False):

redis/utils.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from contextlib import contextmanager
2+
from functools import wraps
23
from typing import Any, Dict, Mapping, Union
34

45
try:
@@ -80,3 +81,30 @@ def merge_result(command, res):
8081
result.add(value)
8182

8283
return list(result)
84+
85+
86+
def warn_deprecated(name, reason="", version="", stacklevel=2):
87+
import warnings
88+
89+
msg = f"Call to deprecated {name}."
90+
if reason:
91+
msg += f" ({reason})"
92+
if version:
93+
msg += f" -- Deprecated since version {version}."
94+
warnings.warn(msg, category=DeprecationWarning, stacklevel=stacklevel)
95+
96+
97+
def deprecated_function(reason="", version="", name=None):
98+
"""
99+
Decorator to mark a function as deprecated.
100+
"""
101+
102+
def decorator(func):
103+
@wraps(func)
104+
def wrapper(*args, **kwargs):
105+
warn_deprecated(name or func.__name__, reason, version, stacklevel=3)
106+
return func(*args, **kwargs)
107+
108+
return wrapper
109+
110+
return decorator

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
async-timeout>=4.0.2
2-
deprecated>=1.2.3
32
typing-extensions; python_version<"3.8"

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
author_email="oss@redis.com",
3333
python_requires=">=3.7",
3434
install_requires=[
35-
"deprecated>=1.2.3",
3635
'importlib-metadata >= 1.0; python_version < "3.8"',
3736
'typing-extensions; python_version<"3.8"',
3837
"async-timeout>=4.0.2",

0 commit comments

Comments
 (0)