[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:
- Made
GenericAliassubclassable. - Subclassed it in
collections.abc.Callable's__class_getitem__to allow for consistentency withtyping.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)
- Added tests for the above.
- 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)