◐ Shell
clean mode source ↗

[3.9] bpo-42195: Ensure consistency of Callable's __args__ in collections.abc and typing (GH-23060) by Fidget-Spinner · Pull Request #23765 · python/cpython

This patch fixes bpo-42195 via changing the GenericAlias builtin and subclassing for collections.abc.Callable's __class_getitem__. The changes are:

  1. Made GenericAlias subclassable.
  2. Subclassed it in collections.abc.Callable's __class_getitem__ to allow for consistentency with typing.Callable's __args__. This includes flattening the __args__.
>>> import collections.abc
>>> alias = collections.abc.Callable[[int, str], dict]

>>> alias
collections.abc.Callable[[int, str], dict]

>>> alias.__args__
(int, str, dict)
  1. Added tests for the above.
  2. Loosened type checks for Callable's argtypes in Callable[[argtypes], resulttype] to prepare for PEP 612.

https://bugs.python.org/issue42195

(cherry picked from commit 463c7d3)