Skip to content

abstract class shouldn't be considered Callable #12361

@beauxq

Description

@beauxq

Bug Report

An abstract class fits the typing for Callable.

To Reproduce

import abc
from typing import Callable


class A(abc.ABC):
    @abc.abstractmethod
    def m(self) -> None:
        ...


class C(A):
    def m(self) -> None:
        pass


def f() -> A:
    return C()


def t(x: Callable[[], A]) -> None:
    x()


def main() -> None:
    t(f)
    t(C)
    t(A)  # should give typing error - A is not callable because it can't be instantiated
    A()  # mypy correctly reports that A can't be instantiated


if __name__ == "__main__":
    main()

Expected Behavior

mypy should report a typing error if an abstract class is put where a Callable should go

Actual Behavior

mypy doesn't report any error if an abstract class is put where a Callable should go

Your Environment

  • Mypy version used: 0.910
  • Python version used: 3.8.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions