Skip to content

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

Description

@KotlinIsland
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

Activity

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

Metadata

Metadata

Assignees

Labels

bugmypy got something wrong

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions