[issue42195] Inconsistent __args__ between typing.Callable and collections.abc.Callable

Ken Jin report at bugs.python.org
Mon Nov 30 21:24:57 EST 2020


Ken Jin <kenjin4096 at gmail.com> added the comment:

FWIW, current code for extracting args type and return type from Callable seems to be something like this (at least from the typing module):

arg_types = __args__[:-1]
return_type = __args__[-1]

Once ParamSpec is added in, library authors would need to check specifically for that in arg_types and return_types. Other than that, I don't have enough expertise or experience to say what will/won't break. 

IMO a flat tuple is ok for now: AFAIK (and I might be completely wrong here), most runtime type checking libraries I've used don't validate the arguments passed in because being too strict may interfere with keyword arguments. (Eg. Callable in Pydantic https://pydantic-docs.helpmanual.io/usage/types/#callable). So the slightly more inconvenient way of reading Callable's __args__ seems to be an acceptable tradeoff for backwards compatibility and simplicity.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42195>
_______________________________________


More information about the Python-bugs-list mailing list