Skip to content

Change type hints with possible None args or return types to be annotated with Optional - includes commands in core.py and json commands #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

Merged
merged 14 commits into from
May 8, 2025

Conversation

kesha1225
Copy link
Contributor

@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.

@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
Contributor Author

fingers crossed this one gets merged after the latest update

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.

Just one more changes and it is done :)

@petyaslavova petyaslavova added the maintenance Maintenance (CI, Releases, etc) label Apr 29, 2025
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.

I added a comment for one of the test failures I saw, can you please also check the linters - there are some formatting errors as well?

@petyaslavova petyaslavova requested a review from Copilot May 7, 2025 15:47
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 type annotations for various Redis command methods to use Optional types instead of Union[..., None] or plain defaults where applicable.

  • Updates type hints in JSON command methods in redis/commands/json/commands.py
  • Updates type hints in core Redis commands in redis/commands/core.py
  • Documents the change in the CHANGES file

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
redis/commands/json/commands.py Updated return type annotations for methods in JSON commands
redis/commands/core.py Changed method signatures to utilize Optional for nullable parameters
CHANGES Updated changelog to reflect the changes in type annotations

@petyaslavova petyaslavova changed the title Change 'zrange' args type hints - adding Optional type hint for args that can be None Change typehints with possible None args or return types to be annotated with Optional - includes commands in core.py and json commands May 8, 2025
@petyaslavova petyaslavova changed the title Change typehints with possible None args or return types to be annotated with Optional - includes commands in core.py and json commands Change type hints with possible None args or return types to be annotated with Optional - includes commands in core.py and json commands May 8, 2025
@petyaslavova petyaslavova merged commit cfe0695 into redis:master May 8, 2025
100 of 103 checks passed
petyaslavova pushed a commit to Kakadus/redis-py that referenced this pull request May 13, 2025
…ated with Optional - includes commands in core.py and json commands (redis#3610)

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

* fix(redis-client): normalize optional parameter annotations

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.

* commit message: fix(redis-client): normalize optional parameter annotations 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]

* fix(redis-client): replace Optional[None] with Optional[int] for numeric parameters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Maintenance (CI, Releases, etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants