Skip to content

Commit

Permalink
Remove deprecated dependency
Browse files Browse the repository at this point in the history
No need for an external library just for 5 annotations.
  • Loading branch information
akx committed Oct 27, 2022
1 parent bea00b1 commit db0e772
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Fix RedisCluster to immediately raise AuthenticationError without a retry
* ClusterPipeline Doesn't Handle ConnectionError for Dead Hosts (#2225)
* Remove compatibility code for old versions of Hiredis, drop Packaging dependency
* The `deprecated` library is no longer a dependency

* 4.1.3 (Feb 8, 2022)
* Fix flushdb and flushall (#1926)
Expand Down
6 changes: 2 additions & 4 deletions redis/commands/bf/commands.py
Original file line number Diff line number Diff line change
@@ -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, deprecated_function

BF_RESERVE = "BF.RESERVE"
BF_ADD = "BF.ADD"
Expand Down Expand Up @@ -327,7 +325,7 @@ 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")
@deprecated_function(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`.
Expand Down
11 changes: 5 additions & 6 deletions redis/commands/json/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 deprecated_function

from ._util import JsonType
from .decoders import decode_dict_keys
Expand Down Expand Up @@ -137,7 +136,7 @@ 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")
@deprecated_function(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``.
Expand Down Expand Up @@ -368,19 +367,19 @@ def debug(
pieces.append(str(path))
return self.execute_command("JSON.DEBUG", *pieces)

@deprecated(
@deprecated_function(
version="4.0.0", reason="redisjson-py supported this, call get directly."
)
def jsonget(self, *args, **kwargs):
return self.get(*args, **kwargs)

@deprecated(
@deprecated_function(
version="4.0.0", reason="redisjson-py supported this, call get directly."
)
def jsonmget(self, *args, **kwargs):
return self.mget(*args, **kwargs)

@deprecated(
@deprecated_function(
version="4.0.0", reason="redisjson-py supported this, call get directly."
)
def jsonset(self, *args, **kwargs):
Expand Down
28 changes: 28 additions & 0 deletions redis/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from contextlib import contextmanager
from functools import wraps
from typing import Any, Dict, Mapping, Union

try:
Expand Down Expand Up @@ -80,3 +81,30 @@ def merge_result(command, res):
result.add(value)

return list(result)


def warn_deprecated(name, reason="", version="", stacklevel=2):
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=stacklevel)


def deprecated_function(reason="", version="", name=None):
"""
Decorator to mark a function as deprecated.
"""

def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
warn_deprecated(name or func.__name__, reason, version, stacklevel=3)
return func(*args, **kwargs)

return wrapper

return decorator
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
async-timeout>=4.0.2
deprecated>=1.2.3
typing-extensions; python_version<"3.8"
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
author_email="oss@redis.com",
python_requires=">=3.7",
install_requires=[
"deprecated>=1.2.3",
'importlib-metadata >= 1.0; python_version < "3.8"',
'typing-extensions; python_version<"3.8"',
"async-timeout>=4.0.2",
Expand Down

0 comments on commit db0e772

Please sign in to comment.