Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If Callable type is incompatible with a callable protocol, show signature of __call__ #17840

Open
JukkaL opened this issue Sep 27, 2024 · 4 comments

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Sep 27, 2024

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.)

@tasfia8
Copy link

tasfia8 commented Sep 29, 2024

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?

@tasfia8
Copy link

tasfia8 commented Sep 30, 2024

Could I be assigned this?

@JelleZijlstra
Copy link
Member

Feel free to work on this and send a PR!

@ChengPuPu
Copy link

Hello, Is it still open, Can I do this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants