[issue42102] Make builtins.callable "generic"

Guido van Rossum report at bugs.python.org
Mon Nov 23 00:21:48 EST 2020


Guido van Rossum <guido at python.org> added the comment:

Hm. Shantanu's list shows that the next thing we should make usable without importing typing is Any. (I haven't any idea how to do that other than just making it a builtin.) But after that we should definitely tackle Callable, and the obvious way to do it is to make callable indexable. But does that mean it has to be a type? I don't think so -- it just has to be an object whose class defines both __call__ and __getitem__. Pseudo code:

class callable:
    def __call__(self, thing):
        return hasattr(thing, "__call__")
    def __getitem__(self, index):
        # returns a types.GenericAlias instance
        # (or a subclass thereof)

I honestly don't think that we should support isinstance(x, callable) even if some people think that that should work.

In any case, we should first answer the questions that are still open for issue 42195 -- what should __args__ for [cC]allable[[int, int], str] be? (int, int, str) or ((int, int), str) or ([int, int], str) or (Tuple[int, int], str) are all still on the table. Please refer to that issue.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42102>
_______________________________________


More information about the Python-bugs-list mailing list