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

collections.abc.Callable incorrectly considered a _SpecialForm #11766

Closed
randolf-scholz opened this issue Apr 15, 2024 · 2 comments
Closed

collections.abc.Callable incorrectly considered a _SpecialForm #11766

randolf-scholz opened this issue Apr 15, 2024 · 2 comments

Comments

@randolf-scholz
Copy link
Contributor

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)
@AlexWaygood
Copy link
Member

Possibly a duplicate of #6257?

@JelleZijlstra
Copy link
Member

Callable is indeed a special form in the type system (https://typing.readthedocs.io/en/latest/spec/annotations.html#expression-grammar). As such, type checkers need to special case it. Mypy here may not be special casing it correctly, but that's a bug in mypy, not typeshed.

If you have a concrete proposal for a change to typeshed that would help mypy here, we can consider it, but so far I don't see any.

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants