Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request check-list
Reviewed and checked all of these items:
Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?- no API changeschecks.py
file example to the repo?Description of change
Hello, there're some issues with type annotations: #2399 #3169
Example:
We can see that sync redis client may return awaitable result, but it will never do.
This is made for compatibility with async redis, but it introduces some challenges when checking code with static type checkers like mypy.
Also it's
Any
instead ofstr
orbytes
because we can't predict, ifdecode_responses
isTrue
orFalse
- it'll be addressed later.I'd like to make it work this way:
I started reworking annotations, so type annotations for sync / async redis work as expected - sync redis doesn't return
Awaitable
, async redis returnsAwaitable
.Important
The goal is not to make the whole
redis-py
source code mypy-comliant and fully annotated.The goal is to make usage of
redis-py
in python projects compatible with mypy - make return type annotations more precise. So devs don't need to addcast
s andassert
s to their code.Example code. where I checked new typing
File:
checks.py
:I checked it with mypy with
strict=True
enabled:mypy --strict checks.py
, added comments to the code example above.If these changes are ok for
redis-py
, I'll continue working on the update.There's one major issue: these annotations are ok when
decode_responses=True
, but if not passed, ordecode_responses=False
, then some methods will returnbytes
instead ofstr
- I'm working on a solution for this.Also I fixed parsing for some commands which should return bools: 23ff994