Skip to content

collections.abc.Callable incorrectly considered a _SpecialForm #11766

Closed as not planned
@randolf-scholz

Description

@randolf-scholz

Typeshed currently treats collections.abc.Callable as equivalent to typing.Callable, but they aren't

import typing
from collections import abc
assert isinstance(abc.Callable, type)  # ✅
assert isinstance(typing.Callable, type)  # ❌

This causes a very annoying bug: python/mypy#14014

collections.abc.Callable is a subclass of ABCMeta:, a real type that can be used in match-case and isinstance/issubclass.

class Callable(metaclass=ABCMeta):


    __slots__ = ()


    @abstractmethod
    def __call__(self, *args, **kwds):
        return False


    @classmethod
    def __subclasshook__(cls, C):
        if cls is Callable:
            return _check_methods(C, "__call__")
        return NotImplemented


    __class_getitem__ = classmethod(_CallableGenericAlias)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions