Skip to content

typing: Fix signature of Redis.transaction#4002

Open
stephenfin wants to merge 3 commits intoredis:masterfrom
stephenfin:typing
Open

typing: Fix signature of Redis.transaction#4002
stephenfin wants to merge 3 commits intoredis:masterfrom
stephenfin:typing

Conversation

@stephenfin
Copy link
Copy Markdown

@stephenfin stephenfin commented Mar 13, 2026

Description of change

The return type depends on the value of the value_from_callable kwarg. Indicate this with type hinting.

Pull Request check-list

  • 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

Low Risk
Primarily type-hinting changes; runtime logic is unchanged aside from moving shard_hint, value_from_callable, and watch_delay into explicit keyword parameters, which is unlikely to affect callers using them as kwargs.

Overview
Improves typing for Redis.transaction by introducing @overload signatures that make the return type depend on value_from_callable (returns List[Any] vs the callable’s return type T).

Updates the concrete method signature to use a generic TypeVar, typed watches, and explicit keyword parameters for shard_hint, value_from_callable, and watch_delay instead of pulling them from **kwargs.

Reviewed by Cursor Bugbot for commit 0a429bd. Bugbot is set up for automated code reviews on this repo. Configure here.

The return type depends on the value of the value_from_callable kwarg.
Indicate this with type hinting.

Signed-off-by: Stephen Finucane <stephen@that.guru>
@jit-ci
Copy link
Copy Markdown

jit-ci bot commented Mar 13, 2026

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

@petyaslavova
Copy link
Copy Markdown
Collaborator

Hi @stephenfin , thank you for your contribution! We will have a look at it.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 0a429bd. Configure here.

Comment thread redis/client.py
*watches: str | None,
shard_hint: Any = None,
value_from_callable: bool = False,
watch_delay: int | None = None,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

watch_delay type too narrow compared to async counterpart

Medium Severity

The watch_delay parameter is typed as int | None in all three signatures (both overloads and the implementation), but the async version of this same method in redis/asyncio/client.py correctly types it as Optional[float]. Since time.sleep() accepts float values, the int annotation is too restrictive and would cause type checkers to reject valid fractional-second delays like 0.5. This needs to be float | None to match the async counterpart and the actual runtime behavior.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0a429bd. Configure here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'd actually spotted and fixed this locally (albeit I went with int | float | None) as part of a larger series but I hadn't pushed it since I wasn't sure this was going to be merged.

@petyaslavova it looks like you're doing most of the type work here. Would you like to take ownership of this and fix as necessary? Or would you rather I push the fix? Also, I have a larger patch to make many of the *Commands classes and make them subclass Generic[AnyStr] since they accept and return both str and bytes. Do you want that or are you planning to fix that yourself?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants