Closed
Description
Bug Report
ParamSpec feature doesn't seem to work well when used with Protocol.
To Reproduce
from typing import Any, ParamSpec, Protocol
P = ParamSpec("P")
class Runnable(Protocol[P]):
def run(self, *args: P.args, **kwargs: P.kwargs) -> Any:
...
def foo(func: Runnable) -> int:
...
class A:
def run(self, i: int) -> Any:
...
foo(A())
Expected Behavior
IMO, mypy shouldn't report any bug, do you agree ?
Actual Behavior
mypy logs an error, which means mypy doesn't recognize A as implementing the Runnable
protocol (which it does)
commands/typing_debug.py:20: error: Argument 1 to "foo" has incompatible type "A"; expected "Runnable[Any]"
commands/typing_debug.py:20: note: Following member(s) of "A" have conflicts:
commands/typing_debug.py:20: note: Expected:
commands/typing_debug.py:20: note: def run(self, *args: Any, **kwargs: Any) -> Any
commands/typing_debug.py:20: note: Got:
commands/typing_debug.py:20: note: def run(self, i: int) -> Any
However if foo
is defined as
def foo(func: Runnable[int]) -> int:
...
mypy doesn't report any error.
Your Environment
- Mypy version used: 0.971
- Mypy command-line flags: no flag
- Mypy configuration options from
mypy.ini
(and other config files): no config file - Python version used: 3.10.2
- Operating system and version: MacOS 12.6