Skip to content

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

Open
coderabbit-test/mypy
#10
@KotlinIsland

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

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