Skip to content

typing.get_args(Callable) fails #84578

Description

@serhiy-storchaka
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']

    Activity

    1. serhiy-storchaka commented on Apr 26, 2020

      @serhiy-storchaka
      MemberAuthor
      >>> 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?

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Apr 26, 2020
    3. gvanrossum commented on Apr 26, 2020

      @gvanrossum
      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.

    4. ilevkivskyi commented on Apr 26, 2020

      @ilevkivskyi
      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.

    5. gvanrossum commented on Apr 26, 2020

      @gvanrossum
      Member

      Agreed, that's better!

    6. serhiy-storchaka commented on Apr 26, 2020

      @serhiy-storchaka
      MemberAuthor

      get_args(List) == (T,)

    7. ilevkivskyi commented on Apr 26, 2020

      @ilevkivskyi
      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.

    8. serhiy-storchaka commented on Apr 27, 2020

      @serhiy-storchaka
      MemberAuthor

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

    9. changed the title [-]get_args(Callable) fails[/-] [+]typing.get_args(Callable) fails[/+] on May 1, 2020
    10. changed the title [-]get_args(Callable) fails[/-] [+]typing.get_args(Callable) fails[/+] on May 1, 2020
    11. gvanrossum commented on May 1, 2020

      @gvanrossum
      Member

      @serhiy is this fixed by PR 19720?

    12. serhiy-storchaka commented on May 2, 2020

      @serhiy-storchaka
      MemberAuthor

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

    13. serhiy-storchaka commented on May 2, 2020

      @serhiy-storchaka
      MemberAuthor

      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

    14. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.8 (EOL)end of life3.9 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions