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

Conversation

mharding-hpe
Copy link
Contributor

@mharding-hpe mharding-hpe commented Jul 7, 2025

Pull Request check-list

  • Do tests and lints pass with this change?

Everything passes except one standalone test: tests/test_commands.py::TestRedisCommands::test_psync

However, I ran the tests on the master branch of the repo and got the same result, so I assume that test failure is unrelated to my changes.

  • Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?

mharding-hpe#2

  • Is the new or changed code fully tested?

  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

N.A

  • Is there an example added to the examples folder (if applicable)?

N/A

Description of change

Opened to resolve issue #3700

Added type annotations to the deprecated_args decorator, to clarify that the type of callable will not be modified by anything inside the different functions (thus preserving its original signature). Without this, mypy interprets the type of redis.Redis() to be Any.

This issue was introduced between v6.0.0b2 and v6.0.0. So ideally this fix would be backported to the v6.0 and v6.1 branches, but I don't know the policy for that in this project.

@petyaslavova
Copy link
Collaborator

Hi @mharding-hpe, thank you for your contribution! It will be reviewed shortly.
Regarding backporting to previous versions: as per our policy, we only backport critical fixes, so this change will be included in newer versions only.

@petyaslavova petyaslavova requested a review from Copilot July 8, 2025 11:49
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds precise type annotations to the deprecated_args decorator so that wrapped functions retain their original signatures for tools like MyPy.

  • Introduces a TypeVar C bound to Callable for preserving callables' types
  • Annotates deprecated_args to return Callable[[C], C] and its inner decorator to accept and return C
  • Imports the necessary types and updates the typing imports
Comments suppressed due to low confidence (1)

redis/utils.py:4

  • Importing Callable from collections.abc may not support subscripting for type annotations on all supported Python versions. Consider importing Callable from typing instead to ensure Callable[[C], C] works universally.
from collections.abc import Callable

@petyaslavova petyaslavova merged commit 310813a into redis:master Jul 9, 2025
67 of 68 checks passed
@petyaslavova petyaslavova added bug-fix maintenance Maintenance (CI, Releases, etc) labels Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-fix maintenance Maintenance (CI, Releases, etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants