-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
Methods on protocols with a __call__
method cannot infer the type of self
as callable in other methods.
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.11&flags=strict&gist=7234281168a0762dd9a81b1f10d8a96a
from typing import Callable, ParamSpec, Protocol, TypeVar
Params = ParamSpec("Params")
Result = TypeVar("Result", covariant=True)
class FancyMethod(Protocol):
def __call__(self, arg1: int, arg2: str) -> list[float]:
"""
Calling me results in a very specific signature.
"""
def returnMe(self: Callable[Params, Result]) -> Callable[Params, Result]:
...
def externalGet(self: Callable[Params, Result]) -> Callable[Params, Result]:
return self
Expected Behavior
I would expect that this would be inferred in returnMe
the same way that it would be in externalGet
.
Actual Behavior
main.py:13: error: The erased type of self "def (*Params.args, **Params.kwargs) -> Result`-2" is not a supertype of its class "__main__.FancyMethod" [misc]
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong