redis / redis-py

Redis Python client
MIT License
12.4k stars 2.48k forks source link

Add typings to the `redis.Redis` class #3252

Open bitterteriyaki opened 1 month ago

bitterteriyaki commented 1 month ago

Pull Request check-list

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

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

Description of change

NOTE: This PR adds breaking changes.

This PR aims to add static typings to the redis.client.Redis class. This is still a work in progress and this PR must not be merged yet. Please give me any feedback on that.

bitterteriyaki commented 1 month ago

In some parameters, I don't know what is the proper type. I'll fix these later.

gerzse commented 1 month ago

Hi @bitterteriyaki, thanks for your desire to contribute!

Currently redis-py supports Python 3.8 up to and including 3.11, and support for 3.12 is planned.

In general it's best to use language constructs that work in all these versions. For example Union[str, None] instead of str | None, which is available only since 3.10. The Self construct can be made available in versions earlier than 3.11?

bitterteriyaki commented 1 month ago

Currently redis-py supports Python 3.8 up to and including 3.11, and support for 3.12 is planned.

Hi, @gerzse. Thank you for the answer. Since Python 3.7 was dropped, It would be nice to update the documentation.

In general it's best to use language constructs that work in all these versions. For example Union[str, None] instead of str | None, which is available only since 3.10.

Alright. I'll be changing this.

The Self construct can be made available in versions earlier than 3.11?

According to the typing documentation, no. I'll also be changing this.

bitterteriyaki commented 1 month ago

Instead of typing.Self, I am using from __future__ import annotations which is available for old Python versions and is a library for "future" which is not available for these versions.