Skip to content

Annotate deprecated_args decorator to preserve wrapped function type signature #3701

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 2 commits into from
Jul 9, 2025
Merged
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
10 changes: 7 additions & 3 deletions redis/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import datetime
import logging
import textwrap
from collections.abc import Callable
from contextlib import contextmanager
from functools import wraps
from typing import Any, Dict, List, Mapping, Optional, Union
from typing import Any, Dict, List, Mapping, Optional, TypeVar, Union

from redis.exceptions import DataError
from redis.typing import AbsExpiryT, EncodableT, ExpiryT
Expand Down Expand Up @@ -150,18 +151,21 @@ def warn_deprecated_arg_usage(
warnings.warn(msg, category=DeprecationWarning, stacklevel=stacklevel)


C = TypeVar("C", bound=Callable)


def deprecated_args(
args_to_warn: list = ["*"],
allowed_args: list = [],
reason: str = "",
version: str = "",
):
) -> Callable[[C], C]:
"""
Decorator to mark specified args of a function as deprecated.
If '*' is in args_to_warn, all arguments will be marked as deprecated.
"""

def decorator(func):
def decorator(func: C) -> C:
@wraps(func)
def wrapper(*args, **kwargs):
# Get function argument names
Expand Down
Loading