Skip to content

Supply chain risk reduction: remove dependency on library named deprecated #2386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 3 additions & 4 deletions redis/commands/search/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import time
from typing import Dict, Optional, Union

from deprecated import deprecated

from redis.client import Pipeline
from redis.utils import deprecated_function

from ..helpers import parse_to_dict
from ._util import to_string
Expand Down Expand Up @@ -238,7 +237,7 @@ def _add_document_hash(

return self.execute_command(*args)

@deprecated(
@deprecated_function(
version="2.0.0", reason="deprecated since redisearch 2.0, call hset instead"
)
def add_document(
Expand Down Expand Up @@ -294,7 +293,7 @@ def add_document(
**fields,
)

@deprecated(
@deprecated_function(
version="2.0.0", reason="deprecated since redisearch 2.0, call hset instead"
)
def add_document_hash(self, doc_id, score=1.0, language=None, replace=False):
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="[email protected]",
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