Skip to content

Change 'zrange' args type hints - adding Optional type hint for args that can be None #3610

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

kesha1225
Copy link

@kesha1225 kesha1225 commented Apr 19, 2025

Title:
fix(redis-client): change zrange num parameter type to Optional[int]


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)? (https://github.com/kesha1225/redis-py/actions/runs/14544583494)
  • 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)?
  • Was the change added to the CHANGES file?

Description of change

This PR adjusts the signature of the zrange method in redis/commands/core.py, changing the num parameter from a plain int = None to Optional[int] = None.

  • Motivation: align the type annotation with its optional usage and eliminate type‑checking errors.
  • Behavior: no functional change—existing behavior remains identical.
  • Tests & Docs: all existing unit tests and lint checks have been verified to pass; the docstring signature has been updated accordingly.

@@ -4458,7 +4458,7 @@ def zrange(
byscore: bool = False,
bylex: bool = False,
offset: int = None,
num: int = None,
num: Optional[int] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @kesha1225, there are other arguments with the same pattern - where the arguments can be None. Can you please update all of them to be Optional for the zrange and _zrange functions?

Copy link
Author

Choose a reason for hiding this comment

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

Hi @petyaslavova
I replaced every Union[T, None] and bare T=None with Optional[T]=None and updated arrtrim to return Optional[int] instead of List[Optional[int]]. Let me know if you spot anything else. I’m happy to help with any further tweaks.

@petyaslavova petyaslavova changed the title Fix type Change 'zrange' args type hints - adding Optional type hint for args that can be None Apr 22, 2025
Replace all occurrences of Union[T, None] = None and bare T = None
with Optional[T] = None in zrange, _zrange, arrtrim, and other methods
so that type checkers no longer report errors.
Copy link
Collaborator

@petyaslavova petyaslavova left a comment

Choose a reason for hiding this comment

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

You have several places where Union[int, None] is replaced with Optional[None]. Please check them and change to Optional[int]

petyaslavova and others added 3 commits April 24, 2025 16:49
…ations and correct arrtrim return type

body: replaced all Union[T, None] = None and bare T = None with Optional[T] = None; changed arrtrim return annotation to Optional[int]
@kesha1225
Copy link
Author

fingers crossed this one gets merged after the latest update

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.

2 participants