Skip to content

Fixing the return type hint for the transaction method in the standalone client. #3660

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

Conversation

petyaslavova
Copy link
Collaborator

Pull Request check-list

Please make sure to review and check all of these items:

  • Do tests and lints pass with this change?
  • Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Is there an example added to the examples folder (if applicable)?

NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.

Description of change

Fixing the return type hint for the transaction method in the standalone client.
The method returns either the returned response from execute method call which is List[Any] or None, or the response from the provided custom function, which can be anything.

Fixes issue #3631

@petyaslavova petyaslavova added the techdebt Things that can be improved or refactored label May 27, 2025
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 updates the return type hint for the transaction method in the standalone Redis client to reflect that it may return the results of Pipeline.execute(), None, or a custom callback’s return value.

  • Changed the return annotation of transaction from None to Optional[Union[List[Any], Any]]
  • Adjusted the method signature to allow for custom callback return types
Comments suppressed due to low confidence (3)

redis/client.py:454

  • The docstring doesn’t describe the new return values. Please add a Returns: section explaining that this method may return the list from execute, the custom callback’s return value, or None.
"""

redis/client.py:450

  • Add tests covering scenarios where transaction returns the custom callback result, the list from execute, and None. This ensures the new return types are exercised.
def transaction(

redis/client.py:453

  • Ensure that Optional, Union, List, and Any are imported from the typing module (or collections.abc in newer versions) to prevent unresolved references.
) -> Optional[Union[List[Any], Any]]:

redis/client.py Outdated
Comment on lines 452 to 453
self, func: Callable[["Pipeline"], None], *watches, **kwargs
) -> None:
) -> Optional[Union[List[Any], Any]]:
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

The return type hint Optional[Union[List[Any], Any]] can be simplified. Since Any already encompasses List[Any], consider using -> Any or -> Optional[Any]. For stronger typing, introduce a TypeVar for the callback return: e.g.

R = TypeVar('R')
def transaction(self, func: Callable[["Pipeline"], R], *watches, **kwargs) -> Optional[R]:
    ...

Copilot uses AI. Check for mistakes.

@petyaslavova petyaslavova merged commit 6246cba into master May 29, 2025
97 of 100 checks passed
@petyaslavova petyaslavova deleted the ps_fix_standalone_client_transaction_method_teturn_type_annotation branch May 29, 2025 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
techdebt Things that can be improved or refactored
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants