You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>>> from typing import*
>>> get_args(Callable)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/serhiy/py/cpython/Lib/typing.py", line 1412, in get_args
if get_origin(tp) is collections.abc.Callable and res[0] is not Ellipsis:
IndexError: tuple index out of range
Maybe it could return (Ellipsis, Any) in that case. The most general form of Callable is Callable[..., Any] and that's that get_args() returns for that.
I think it should return empty tuple: First, for consistency with other things like get_args(Tuple) == () and get_args(List) == (). Second, although Callable is equivalent to Callable[..., Any] in the static world, authors of some runtime checkers might want to distinguish whether a user wrote one or another.
Oh my, this looks like another bug. I don't have Python 3.8 at hand so just tried typing_inspect on Python 3.6. I think this may be caused by the "double use" of _GenericAlias for which you opened your WIP PR.
New changeset a629d4c by Serhiy Storchaka in branch '3.8':
[3.8] bpo-40398: Fix typing.get_args() for special generic aliases. (GH-19720) (GH-19857) a629d4c
Activity
serhiy-storchaka commentedon Apr 26, 2020
What is the correct behavior?
gvanrossum commentedon Apr 26, 2020
Maybe it could return (Ellipsis, Any) in that case. The most general form of Callable is Callable[..., Any] and that's that get_args() returns for that.
ilevkivskyi commentedon Apr 26, 2020
I think it should return empty tuple: First, for consistency with other things like get_args(Tuple) == () and get_args(List) == (). Second, although Callable is equivalent to Callable[..., Any] in the static world, authors of some runtime checkers might want to distinguish whether a user wrote one or another.
gvanrossum commentedon Apr 26, 2020
Agreed, that's better!
serhiy-storchaka commentedon Apr 26, 2020
get_args(List) == (T,)
ilevkivskyi commentedon Apr 26, 2020
Oh my, this looks like another bug. I don't have Python 3.8 at hand so just tried
typing_inspecton Python 3.6. I think this may be caused by the "double use" of _GenericAlias for which you opened your WIP PR.serhiy-storchaka commentedon Apr 27, 2020
New changeset 6292be7 by Serhiy Storchaka in branch 'master':
bpo-40398: Fix typing.get_args() for special generic aliases. (GH-19720)
6292be7
[-]get_args(Callable) fails[/-][+]typing.get_args(Callable) fails[/+][-]get_args(Callable) fails[/-][+]typing.get_args(Callable) fails[/+]gvanrossum commentedon May 1, 2020
@serhiy is this fixed by PR 19720?
serhiy-storchaka commentedon May 2, 2020
Yes, I have not closed this issue yet because it required a manual backporting to 3.8.
serhiy-storchaka commentedon May 2, 2020
New changeset a629d4c by Serhiy Storchaka in branch '3.8':
[3.8] bpo-40398: Fix typing.get_args() for special generic aliases. (GH-19720) (GH-19857)
a629d4c