MCPcopy Index your code
hub / github.com/python/cpython / _CallableType

Class _CallableType

Lib/typing.py:1668–1698  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1666
1667
1668class _CallableType(_SpecialGenericAlias, _root=True):
1669 def copy_with(self, params):
1670 return _CallableGenericAlias(self.__origin__, params,
1671 name=self._name, inst=self._inst)
1672
1673 def __getitem__(self, params):
1674 if not isinstance(params, tuple) or len(params) != 2:
1675 raise TypeError("Callable must be used as "
1676 "Callable[[arg, ...], result].")
1677 args, result = params
1678 # This relaxes what args can be on purpose to allow things like
1679 # PEP 612 ParamSpec. Responsibility for whether a user is using
1680 # Callable[...] properly is deferred to static type checkers.
1681 if isinstance(args, list):
1682 params = (tuple(args), result)
1683 else:
1684 params = (args, result)
1685 return self.__getitem_inner__(params)
1686
1687 @_tp_cache
1688 def __getitem_inner__(self, params):
1689 args, result = params
1690 msg = "Callable[args, result]: result must be a type."
1691 result = _type_check(result, msg)
1692 if args is Ellipsis:
1693 return self.copy_with((_TypingEllipsis, result))
1694 if not isinstance(args, tuple):
1695 args = (args,)
1696 args = tuple(_type_convert(arg) for arg in args)
1697 params = args + (result,)
1698 return self.copy_with(params)
1699
1700
1701class _TupleType(_SpecialGenericAlias, _root=True):

Callers 1

typing.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…