This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: help(list[int]) fails
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: 47042 Superseder:
Assigned To: Nosy List: JelleZijlstra, gvanrossum, miss-islington, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2020-04-15 20:50 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30253 merged serhiy.storchaka, 2021-12-25 12:15
PR 31976 merged serhiy.storchaka, 2022-03-18 13:02
PR 31981 merged miss-islington, 2022-03-18 18:46
Messages (6)
msg366558 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-04-15 20:50
>>> 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
msg366581 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-04-16 08:14
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
msg366609 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-04-16 17:11
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.
msg415473 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2022-03-18 09:05
New changeset cd44afc573e2e2de8d7e5a9119c347373066cd10 by Serhiy Storchaka in branch 'main':
bpo-40296: Fix supporting generic aliases in pydoc (GH-30253)
https://github.com/python/cpython/commit/cd44afc573e2e2de8d7e5a9119c347373066cd10
msg415519 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2022-03-18 18:46
New changeset a5b7678a67ac99edd50822827b772e7d9afc8e64 by Serhiy Storchaka in branch '3.10':
[3.10] bpo-40296: Fix supporting generic aliases in pydoc (GH-30253). (GH-31976)
https://github.com/python/cpython/commit/a5b7678a67ac99edd50822827b772e7d9afc8e64
msg415554 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2022-03-19 15:12
New changeset e207d721fcea01123f0e3edb83b6decdcb5e5e63 by Miss Islington (bot) in branch '3.9':
[3.9] bpo-40296: Fix supporting generic aliases in pydoc (GH-30253). (GH-31976) (GH-31981)
https://github.com/python/cpython/commit/e207d721fcea01123f0e3edb83b6decdcb5e5e63
History
Date User Action Args
2022-04-11 14:59:29adminsetgithub: 84476
2022-03-19 15:13:37serhiy.storchakasetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.10, Python 3.11
2022-03-19 15:12:56serhiy.storchakasetmessages: + msg415554
2022-03-18 18:46:48serhiy.storchakasetmessages: + msg415519
2022-03-18 18:46:42miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request30071
2022-03-18 13:02:29serhiy.storchakasetpull_requests: + pull_request30066
2022-03-18 09:05:27serhiy.storchakasetmessages: + msg415473
2022-03-18 01:11:12JelleZijlstrasetnosy: + JelleZijlstra
2022-03-17 11:04:12serhiy.storchakasetdependencies: + Fix test_html_doc in test_pydoc
2021-12-25 12:15:03serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request28474
2021-10-29 08:41:23serhiy.storchakalinkissue45665 dependencies
2020-04-16 17:11:19gvanrossumsetmessages: + msg366609
2020-04-16 08:14:40serhiy.storchakasetmessages: + msg366581
2020-04-15 20:50:17serhiy.storchakacreate