Repository navigation
typing.get_args(Callable) fails #84578
Description
Activity
>>> 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
What is the correct behavior?
- added3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on 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.
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.
Agreed, that's better!
get_args(List) == (T,)
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.- changed the title
[-]get_args(Callable) fails[/-][+]typing.get_args(Callable) fails[/+]on May 1, 2020 - changed the title
[-]get_args(Callable) fails[/-][+]typing.get_args(Callable) fails[/+]on May 1, 2020 Yes, I have not closed this issue yet because it required a manual backporting to 3.8.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: