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)
| 220 | |
| 221 | |
| 222 | def _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 | |
| 246 | def _type_repr(obj): |
no test coverage detected
searching dependent graphs…