Issue 40296: help(list[int]) fails - Python tracker (original) (raw)

help(list[int]) Traceback (most recent call last): File "", line 1, in 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

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 "", line 1, in TypeError: descriptor 'subclasses' for 'type' objects doesn't apply to a 'types.GenericAlias' object

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.