classification
Title: typing.get_args(Callable) fails
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, levkivskyi, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2020-04-26 16:46 by serhiy.storchaka, last changed 2020-05-02 08:08 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19720 merged serhiy.storchaka, 2020-04-26 19:27
PR 19857 merged serhiy.storchaka, 2020-05-02 06:45
Messages (10)
msg367313 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-04-26 16:46
>>> 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?
msg367322 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-04-26 17:47
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.
msg367327 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2020-04-26 18:38
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.
msg367328 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-04-26 18:39
Agreed, that's better!
msg367329 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-04-26 18:41
get_args(List) == (T,)
msg367331 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2020-04-26 18:56
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.
msg367405 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-04-27 07:27
New changeset 6292be7adf247589bbf03524f8883cb4cb61f3e9 by Serhiy Storchaka in branch 'master':
bpo-40398: Fix typing.get_args() for special generic aliases. (GH-19720)
https://github.com/python/cpython/commit/6292be7adf247589bbf03524f8883cb4cb61f3e9
msg367898 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-05-01 23:24
@Serhiy is this fixed by PR 19720?
msg367919 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-05-02 06:47
Yes, I have not closed this issue yet because it required a manual backporting to 3.8.
msg367920 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-05-02 08:08
New changeset a629d4c63c55ba36be36ff105dfc103b710c9a2d by Serhiy Storchaka in branch '3.8':
[3.8] bpo-40398: Fix typing.get_args() for special generic aliases. (GH-19720) (GH-19857)
https://github.com/python/cpython/commit/a629d4c63c55ba36be36ff105dfc103b710c9a2d
History
Date User Action Args
2020-05-02 08:08:24serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-05-02 08:08:04serhiy.storchakasetmessages: + msg367920
2020-05-02 06:47:42serhiy.storchakasetmessages: + msg367919
2020-05-02 06:45:55serhiy.storchakasetpull_requests: + pull_request19173
2020-05-01 23:24:47gvanrossumsetmessages: + msg367898
2020-05-01 22:07:00terry.reedysettitle: get_args(Callable) fails -> typing.get_args(Callable) fails
2020-04-27 07:27:29serhiy.storchakasetmessages: + msg367405
2020-04-26 19:27:10serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request19042
2020-04-26 18:56:43levkivskyisetmessages: + msg367331
2020-04-26 18:41:38serhiy.storchakasetmessages: + msg367329
2020-04-26 18:39:19gvanrossumsetmessages: + msg367328
2020-04-26 18:38:25levkivskyisetmessages: + msg367327
2020-04-26 17:47:53gvanrossumsetmessages: + msg367322
2020-04-26 16:46:07serhiy.storchakacreate