-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add more stubs for redis-py #4480
Conversation
I've tested these stubs against my own project here: brainix/pottery#221 The output is clean for all these new stubs when running `$ mypy --strict`.
16b61cf
to
8c67a96
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! A few remarks below.
alpha: bool = ..., | ||
store: Optional[_Key] = ..., | ||
groups: Optional[bool] = ..., | ||
) -> Union[List[bytes], int]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the result type depends on whether store
is given, we should use overloads to choose the right type (most arguments omitted in the example for brevity):
@overload
def sort(
self,
name: _Key,
start: Optional[int] = ...,
# etc.
store: None = ...,
groups: Optional[bool] = ...,
) -> List[bytes]: ...
@overload
def sort(
self,
name: _Key,
start: Optional[int] = ...,
# etc. with default
*,
store: _Key,
groups: Optional[bool] = ...,
) -> int: ...
@overload
def sort(
self,
name: _Key,
start: Optional[int],
# etc. without default
store: _Key,
groups: Optional[bool] = ...,
) -> int: ...
Unfortunately we need to overloads for the second case, otherwise we'd have a syntax error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch. However, I'm a little stuck. Whenever I try to implement this solution, I get the following errors:
stubs/redis/client.pyi:190: error: Overloaded function signatures 1 and 2 overlap with incompatible return types
stubs/redis/client.pyi:190: error: Overloaded function signatures 1 and 3 overlap with incompatible return types
Any tips?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I can't reproduce this here locally, although we sometimes need # type: ignore
when overloading. Could you commit what you have so far? We squash merge anyway.
Addresses this feedback: python/typeshed#4480 (comment)
Addresses this feedback: python/typeshed#4480 (comment)
0d437d9
to
f84a497
Compare
f84a497
to
3b11312
Compare
Addresses this feedback: python/typeshed#4480 (comment)
Addresses this feedback: python/typeshed#4480 (comment)
* Annotate linsert()'s where argument as a Literal[] Addresses this feedback: python/typeshed#4480 (comment) * Annotate sort()'s groups argument as a bool Addresses this feedback: python/typeshed#4480 (comment)
My type annotation stubs made it upstream! python/typeshed#4480 But then I had to install `types-redis` because running Mypy 0.901 gave me these error messages: ``` Running static type checks pottery/exceptions.py:22: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/monkey.py:37: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/base.py:45: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/base.py:45: note: Hint: "python3 -m pip install types-redis" pottery/base.py:45: note: (or run "mypy --install-types" to install all missing stub packages) pottery/base.py:45: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports pottery/base.py:47: error: Library stubs not installed for "redis.client" (or incompatible with Python 3.9) pottery/set.py:28: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/set.py:29: error: Library stubs not installed for "redis.client" (or incompatible with Python 3.9) pottery/redlock.py:52: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/redlock.py:54: error: Library stubs not installed for "redis.client" (or incompatible with Python 3.9) pottery/nextid.py:37: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/nextid.py:39: error: Library stubs not installed for "redis.client" (or incompatible with Python 3.9) pottery/list.py:30: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/list.py:32: error: Library stubs not installed for "redis.client" (or incompatible with Python 3.9) pottery/hyper.py:25: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/dict.py:31: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/dict.py:32: error: Library stubs not installed for "redis.client" (or incompatible with Python 3.9) pottery/deque.py:25: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/deque.py:26: error: Library stubs not installed for "redis.client" (or incompatible with Python 3.9) pottery/counter.py:30: error: Library stubs not installed for "redis.client" (or incompatible with Python 3.9) pottery/cache.py:36: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/cache.py:37: error: Library stubs not installed for "redis.exceptions" (or incompatible with Python 3.9) Found 20 errors in 12 files (checked 18 source files) ```
My type annotation stubs made it upstream! python/typeshed#4480 But then I had to install `types-redis` because running Mypy 0.901 gave me these error messages: ``` Running static type checks pottery/exceptions.py:22: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/monkey.py:37: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/base.py:45: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/base.py:45: note: Hint: "python3 -m pip install types-redis" pottery/base.py:45: note: (or run "mypy --install-types" to install all missing stub packages) pottery/base.py:45: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports pottery/base.py:47: error: Library stubs not installed for "redis.client" (or incompatible with Python 3.9) pottery/set.py:28: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/set.py:29: error: Library stubs not installed for "redis.client" (or incompatible with Python 3.9) pottery/redlock.py:52: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/redlock.py:54: error: Library stubs not installed for "redis.client" (or incompatible with Python 3.9) pottery/nextid.py:37: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/nextid.py:39: error: Library stubs not installed for "redis.client" (or incompatible with Python 3.9) pottery/list.py:30: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/list.py:32: error: Library stubs not installed for "redis.client" (or incompatible with Python 3.9) pottery/hyper.py:25: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/dict.py:31: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/dict.py:32: error: Library stubs not installed for "redis.client" (or incompatible with Python 3.9) pottery/deque.py:25: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/deque.py:26: error: Library stubs not installed for "redis.client" (or incompatible with Python 3.9) pottery/counter.py:30: error: Library stubs not installed for "redis.client" (or incompatible with Python 3.9) pottery/cache.py:36: error: Library stubs not installed for "redis" (or incompatible with Python 3.9) pottery/cache.py:37: error: Library stubs not installed for "redis.exceptions" (or incompatible with Python 3.9) Found 20 errors in 12 files (checked 18 source files) ```
I've tested these stubs against my own project here:
brainix/pottery#221
The output is clean for all these new stubs when running
$ mypy --strict
.