Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typing.get_args(Callable) fails #84578

Closed
serhiy-storchaka opened this issue Apr 26, 2020 · 10 comments
Closed

typing.get_args(Callable) fails #84578

serhiy-storchaka opened this issue Apr 26, 2020 · 10 comments
Labels
3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 40398
Nosy @gvanrossum, @serhiy-storchaka, @ilevkivskyi
PRs
  • bpo-40398: Fix typing.get_args() for special generic aliases. #19720
  • [3.8] bpo-40398: Fix typing.get_args() for special generic aliases. (GH-19720) #19857
  • 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:

    assignee = None
    closed_at = <Date 2020-05-02.08:08:24.496>
    created_at = <Date 2020-04-26.16:46:07.424>
    labels = ['3.8', 'type-bug', 'library', '3.9']
    title = 'typing.get_args(Callable) fails'
    updated_at = <Date 2020-05-02.08:08:24.495>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2020-05-02.08:08:24.495>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-05-02.08:08:24.496>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2020-04-26.16:46:07.424>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40398
    keywords = ['patch']
    message_count = 10.0
    messages = ['367313', '367322', '367327', '367328', '367329', '367331', '367405', '367898', '367919', '367920']
    nosy_count = 3.0
    nosy_names = ['gvanrossum', 'serhiy.storchaka', 'levkivskyi']
    pr_nums = ['19720', '19857']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue40398'
    versions = ['Python 3.8', 'Python 3.9']

    @serhiy-storchaka
    Copy link
    Member Author

    >>> 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?

    @serhiy-storchaka serhiy-storchaka added 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 26, 2020
    @gvanrossum
    Copy link
    Member

    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
    Copy link
    Member

    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
    Copy link
    Member

    Agreed, that's better!

    @serhiy-storchaka
    Copy link
    Member Author

    get_args(List) == (T,)

    @ilevkivskyi
    Copy link
    Member

    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.

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 6292be7 by Serhiy Storchaka in branch 'master':
    bpo-40398: Fix typing.get_args() for special generic aliases. (GH-19720)
    6292be7

    @terryjreedy terryjreedy changed the title get_args(Callable) fails typing.get_args(Callable) fails May 1, 2020
    @terryjreedy terryjreedy changed the title get_args(Callable) fails typing.get_args(Callable) fails May 1, 2020
    @gvanrossum
    Copy link
    Member

    @serhiy is this fixed by PR 19720?

    @serhiy-storchaka
    Copy link
    Member Author

    Yes, I have not closed this issue yet because it required a manual backporting to 3.8.

    @serhiy-storchaka
    Copy link
    Member Author

    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

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants