-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Open
Description
Version:
5.0.0
Platform:
python 3.10.12
WSL/Ubuntu 20.04
Description:
Both mypy and pyright result in an error with the following code in test.py
from typing import Protocol
from redis import Redis
class RedisLikeSync(Protocol):
def get(self, name: str | bytes) -> bytes | None:
...
def foo(r: RedisLikeSync):
return r.get("foo")
r = Redis()
foo(r)
To reproduce:
pyenv shell 3.10.12
python -m venv venv
. venv/bin/activate
pip install -U pip
pip install redis==5.0.0 mypy pyrightResult of mypy test.py
test.py:15: error: Argument 1 to "foo" has incompatible type "Redis"; expected "RedisLikeSync" [arg-type]
test.py:15: note: Following member(s) of "Redis" have conflicts:
test.py:15: note: Expected:
test.py:15: note: def get(self, name: str | bytes) -> bytes | None
test.py:15: note: Got:
test.py:15: note: def get(self, name: bytes | str | memoryview) -> Awaitable[Any] | Any
Result of pyright test.py
/home/mshantz/typing/test.py
/home/mshantz/typing/test.py:15:5 - error: Argument of type "Redis" cannot be assigned to parameter "r" of type "RedisLikeSync" in function "foo"
"Redis" is incompatible with protocol "RedisLikeSync"
"get" is an incompatible type
Type "(name: KeyT) -> ResponseT" cannot be assigned to type "(name: str | bytes) -> (bytes | None)"
Function return type "ResponseT" is incompatible with type "bytes | None" (reportGeneralTypeIssues)
1 error, 0 warnings, 0 informations
After pip install types-redis, both checks come up clean.
❯ mypy test.py
Success: no issues found in 1 source file
❯ pyright test.py
0 errors, 0 warnings, 0 informations
Since types-redis indicates that it should be removed as of version 5.0.0 of this library, this inconsistency is backwards incompatible...
from https://pypi.org/project/types-redis/
Note: The redis package includes type annotations or type stubs since version 5.0.0. Please uninstall the types-redis package if you use this or a newer version.
gazorby, jimjkelly, alisterd51, elpablete, vlcek and 19 more
Metadata
Metadata
Assignees
Labels
No labels