Skip to content

help(list[int]) fails #84476

New issue

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

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

Already on GitHub? # to your account

Closed
Tracked by #89828
serhiy-storchaka opened this issue Apr 15, 2020 · 6 comments
Closed
Tracked by #89828

help(list[int]) fails #84476

serhiy-storchaka opened this issue Apr 15, 2020 · 6 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 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 40296
Nosy @gvanrossum, @serhiy-storchaka, @JelleZijlstra, @miss-islington
PRs
  • bpo-40296: Fix supporting generic aliases in pydoc #30253
  • [3.10] bpo-40296: Fix supporting generic aliases in pydoc (GH-30253). #31976
  • [3.9] [3.10] bpo-40296: Fix supporting generic aliases in pydoc (GH-30253). (GH-31976) #31981
  • Dependencies
  • bpo-47042: Fix test_html_doc in test_pydoc
  • 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 2022-03-19.15:13:37.231>
    created_at = <Date 2020-04-15.20:50:17.005>
    labels = ['type-bug', 'library', '3.9', '3.10', '3.11']
    title = 'help(list[int]) fails'
    updated_at = <Date 2022-03-19.15:13:37.230>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2022-03-19.15:13:37.230>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-03-19.15:13:37.231>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2020-04-15.20:50:17.005>
    creator = 'serhiy.storchaka'
    dependencies = ['47042']
    files = []
    hgrepos = []
    issue_num = 40296
    keywords = ['patch']
    message_count = 6.0
    messages = ['366558', '366581', '366609', '415473', '415519', '415554']
    nosy_count = 4.0
    nosy_names = ['gvanrossum', 'serhiy.storchaka', 'JelleZijlstra', 'miss-islington']
    pr_nums = ['30253', '31976', '31981']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue40296'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @serhiy-storchaka
    Copy link
    Member Author

    >>> help(list[int])
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/serhiy/py/cpython/Lib/_sitebuiltins.py", line 103, in __call__
        return pydoc.help(*args, **kwds)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1905, in __call__
        self.help(request)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1964, in help
        else: doc(request, 'Help on %s:', output=self._output)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1684, in doc
        pager(render_doc(thing, title, forceload))
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1677, in render_doc
        return title % desc + '\n\n' + renderer.document(object, name)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 381, in document
        if inspect.isclass(object): return self.docclass(*args)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1251, in docclass
        (str(cls.__name__) for cls in type.__subclasses__(object)
    TypeError: descriptor '__subclasses__' for 'type' objects doesn't apply to a 'types.GenericAlias' object

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

    The problem is that isinstance(list[int], type) returns True, but list[int] is not actually an instance of type.

    >>> isinstance(list[int], type)
    True
    >>> issubclass(type(list[int]), type)
    False
    >>> type.__subclasses__(list[int])
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: descriptor '__subclasses__' for 'type' objects doesn't apply to a 'types.GenericAlias' object

    @gvanrossum
    Copy link
    Member

    Yeah, I think help() or pydoc needs to special-case this. (Didn't your other PR attempt to fix this?)

    Note that issubclass(list[int].__class__, type) returns True -- the __class__ attribute in this case is taken from __origin__, while type() returns the "true" class.

    I don't know what to do about __subclasses__ -- I expect we should just let it be this way.

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset cd44afc by Serhiy Storchaka in branch 'main':
    bpo-40296: Fix supporting generic aliases in pydoc (GH-30253)
    cd44afc

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset a5b7678 by Serhiy Storchaka in branch '3.10':
    [3.10] bpo-40296: Fix supporting generic aliases in pydoc (GH-30253). (GH-31976)
    a5b7678

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset e207d72 by Miss Islington (bot) in branch '3.9':
    [3.9] bpo-40296: Fix supporting generic aliases in pydoc (GH-30253). (GH-31976) (GH-31981)
    e207d72

    @serhiy-storchaka serhiy-storchaka added 3.10 only security fixes 3.11 only security fixes labels Mar 19, 2022
    @serhiy-storchaka serhiy-storchaka added 3.10 only security fixes 3.11 only security fixes labels Mar 19, 2022
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    # for free to join this conversation on GitHub. Already have an account? # to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 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

    2 participants