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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

(馃悶) Protocol compatibility is broken for __call__(self, *args: Any) #16568

Open
KotlinIsland opened this issue Nov 26, 2023 · 4 comments
Open
Labels
bug mypy got something wrong

Comments

@KotlinIsland
Copy link
Contributor

KotlinIsland commented Nov 26, 2023

# mypy: disable-error-code=empty-body
from __future__ import annotations

from typing import Any, Protocol

class A(Protocol):
    def __call__(self, *args: Any) -> None: ...

class B1(A):
    def __call__(self, x: int) -> None: ...  # no error

class B2:
    def __call__(self, x: int) -> None: ...

a: A = B2()  # Incompatible types in assignment (expression has type "B2", variable has type "A")  [assignment]

@ilevkivskyi

@KotlinIsland KotlinIsland added the bug mypy got something wrong label Nov 26, 2023
@JelleZijlstra
Copy link
Member

This seems the same as #16569

@KotlinIsland

This comment was marked as outdated.

@erictraut
Copy link

I think this is the same issue as #16569. The protocol should be considered incompatible in both of your examples above, but the (arguably incorrect) special-case handling of *Any discussed in the other issue is resulting in a false negative in the second example above.

For example, mypy reports no errors in this code, but it crashes at runtime.

from typing import Any, Protocol

class A1(Protocol):
    def f(self, *args: Any) -> None:
        ...

class B1:
    def f(self, y: str) -> None:
        ...

def func(a: A1):
    a.f("", "")

func(B1())

@KotlinIsland
Copy link
Contributor Author

I'll close and merge with #16569

@KotlinIsland KotlinIsland closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2023
@KotlinIsland KotlinIsland changed the title (馃悶) Protocol compatibility is broken for non trivial signature that contains *args: Any (馃悶) Protocol compatibility is broken for __call__(self, *args: Any) Nov 27, 2023
@KotlinIsland KotlinIsland reopened this Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants