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

Function _should_unflatten_callable_args

Lib/typing.py:222–243  ·  view source on GitHub ↗

Internal helper for munging collections.abc.Callable's __args__. The canonical representation for a Callable's __args__ flattens the argument types, see https://github.com/python/cpython/issues/86361. For example:: >>> import collections.abc >>> P = ParamSpec('P')

(typ, args)

Source from the content-addressed store, hash-verified

220
221
222def _should_unflatten_callable_args(typ, args):
223 """Internal helper for munging collections.abc.Callable's __args__.
224
225 The canonical representation for a Callable's __args__ flattens the
226 argument types, see https://github.com/python/cpython/issues/86361.
227
228 For example::
229
230 >>> import collections.abc
231 >>> P = ParamSpec('P')
232 >>> collections.abc.Callable[[int, int], str].__args__ == (int, int, str)
233 True
234 >>> collections.abc.Callable[P, str].__args__ == (P, str)
235 True
236
237 As a result, if we need to reconstruct the Callable from its __args__,
238 we need to unflatten it.
239 """
240 return (
241 typ.__origin__ is collections.abc.Callable
242 and not (len(args) == 2 and _is_param_expr(args[0]))
243 )
244
245
246def _type_repr(obj):

Callers 2

_rebuild_generic_aliasFunction · 0.85
get_argsFunction · 0.85

Calls 1

_is_param_exprFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…