Closed
Description
Bug Report
When creating a helper function around a ParamSpec
-based generic I recently stumbled upon a spurious "Incompatible return value type" error.
Mypy seems to (internally) represent CustomCallable[~P]
-parametrized generics as CustomCallable[Callable[P, None]]
instead of just CustomCallable[P]
. This internal representation can be exposed in certain situations though, resulting in false positives such as in the example below.
To Reproduce
from collections.abc import Callable
from typing import Generic, Any
from typing_extensions import ParamSpec
P = ParamSpec("P")
class CustomCallable(Generic[P]):
def __init__(self, func: Callable[P, Any]) -> None: ...
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> None: ...
def func(func: Callable[P, Any]) -> CustomCallable[P]:
# error: Incompatible return value type (got "CustomCallable[Callable[P, None]]", expected "CustomCallable[P]")
return CustomCallable(func)
Your Environment
- Mypy version used: mypy 0.931
- Mypy command-line flags: n.a.
- Mypy configuration options from
mypy.ini
(and other config files): n.a. - Python version used: 3.10.2
- Operating system and version: Windows 10 (build 19044.1526)