Annotate deprecated_args decorator to preserve wrapped function type signature#3701
Merged
petyaslavova merged 2 commits intoredis:masterfrom Jul 9, 2025
Merged
Annotate deprecated_args decorator to preserve wrapped function type signature#3701petyaslavova merged 2 commits intoredis:masterfrom
petyaslavova merged 2 commits intoredis:masterfrom
Conversation
Collaborator
|
Hi @mharding-hpe, thank you for your contribution! It will be reviewed shortly. |
Contributor
There was a problem hiding this comment.
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 Cbound toCallablefor preserving callables' types - Annotates
deprecated_argsto returnCallable[[C], C]and its innerdecoratorto accept and returnC - Imports the necessary types and updates the typing imports
Comments suppressed due to low confidence (1)
redis/utils.py:4
- Importing
Callablefromcollections.abcmay not support subscripting for type annotations on all supported Python versions. Consider importingCallablefromtypinginstead to ensureCallable[[C], C]works universally.
from collections.abc import Callable
petyaslavova
reviewed
Jul 8, 2025
petyaslavova
approved these changes
Jul 9, 2025
petyaslavova
pushed a commit
that referenced
this pull request
Jul 25, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request check-list
Everything passes except one standalone test:
tests/test_commands.py::TestRedisCommands::test_psyncHowever, I ran the tests on the
masterbranch of the repo and got the same result, so I assume that test failure is unrelated to my changes.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
N/A
Description of change
Opened to resolve issue #3700
Added type annotations to the
deprecated_argsdecorator, to clarify that the type of callable will not be modified by anything inside the different functions (thus preserving its original signature). Without this,mypyinterprets the type ofredis.Redis()to beAny.This issue was introduced between
v6.0.0b2andv6.0.0. So ideally this fix would be backported to thev6.0andv6.1branches, but I don't know the policy for that in this project.