If Callable type is incompatible with a callable protocol, show signature of __call__
Feature
We sometimes show the signature of __call__ when a value with a callable type is incompatible with a callback protocol, but not always. At least when checking argument types, we don't show the signature of __call__:
from collections.abc import Callable
from typing import Protocol
class C(Protocol):
def __call__(self, a: int, b: str, c: bytes = b'', /) -> None: ...
def foo(c: C) -> None: ...
f: Callable[[int, str, bytes], None]
c: C
# error: Incompatible types in assignment (expression has type "Callable[[int, str, bytes], None]", variable has type "C")
# note: "C.__call__" has type "Callable[[int, str, DefaultArg(bytes)], None]"
c = f
# error: Argument 1 to "foo" has incompatible type "Callable[[int, str, bytes], None]"; expected "C"
foo(f)
I'd expect mypy to generate the note for the foo(f) line as well.
(Also, DefaultArg(bytes) is awkward in the note, but that's a separate issue.)
Hello JukkaL, nice to read your good first issue! I am a Computer Engineering student and am actively looking for a good open-source first issue that I can work on for my school project. Can I take a look at this?
Could I be assigned this?
Feel free to work on this and send a PR!
Hello, Is it still open, Can I do this issue?
Hello @ChengPuPu ! I am working on this issue.
This was fixed by https://github.com/python/mypy/pull/18214.