Title: help(list[int]) fails
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, serhiy.storchaka
Priority: normal Keywords:

Created on 2020-04-15 20:50 by serhiy.storchaka, last changed 2020-04-16 17:11 by gvanrossum.

Messages (3)
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/", line 103, in __call__
    return*args, **kwds)
  File "/home/serhiy/py/cpython/Lib/", line 1905, in __call__
  File "/home/serhiy/py/cpython/Lib/", line 1964, in help
    else: doc(request, 'Help on %s:', output=self._output)
  File "/home/serhiy/py/cpython/Lib/", line 1684, in doc
    pager(render_doc(thing, title, forceload))
  File "/home/serhiy/py/cpython/Lib/", line 1677, in render_doc
    return title % desc + '\n\n' + renderer.document(object, name)
  File "/home/serhiy/py/cpython/Lib/", line 381, in document
    if inspect.isclass(object): return self.docclass(*args)
  File "/home/serhiy/py/cpython/Lib/", 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)
>>> issubclass(type(list[int]), type)
>>> 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.
Date User Action Args
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