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

(🐞) No error when assigning an non-concrete type object to a Callable variable matching the constructor (Protocol, abstract) #13171

Open
KotlinIsland opened this issue Jul 18, 2022 · 0 comments · May be fixed by #13212
Assignees
Labels
bug mypy got something wrong

Comments

@KotlinIsland
Copy link
Contributor

from typing import Protocol, Callable
from abc import ABC, abstractmethod

class A(ABC):
    @abstractmethod
    def f(self) -> None: ...
    
class P(Protocol):
    a: int

ta1 = A
reveal_type(ta1)
reveal_type(ta1())  # error

ta2: type[A] = A  # error
reveal_type(ta2)
reveal_type(ta2())

ta3: Callable[[], A] = A  # no error
reveal_type(ta3)
reveal_type(ta3())


tp1 = P
reveal_type(tp1)
reveal_type(tp1())  # error

tp2: type[P] = P  # error
reveal_type(tp2)
reveal_type(tp2())

tp3: Callable[[], P] = P  # no error
reveal_type(tp3)
reveal_type(tp3())

playground

@KotlinIsland KotlinIsland added the bug mypy got something wrong label Jul 18, 2022
@sobolevn sobolevn self-assigned this Jul 21, 2022
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

Successfully merging a pull request may close this issue.

2 participants