You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>>> 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
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.
Activity
serhiy-storchaka commentedon Apr 15, 2020
serhiy-storchaka commentedon Apr 16, 2020
The problem is that isinstance(list[int], type) returns True, but list[int] is not actually an instance of type.
gvanrossum commentedon Apr 16, 2020
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 commentedon Mar 18, 2022
New changeset cd44afc by Serhiy Storchaka in branch 'main':
bpo-40296: Fix supporting generic aliases in pydoc (GH-30253)
cd44afc
serhiy-storchaka commentedon Mar 18, 2022
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 commentedon Mar 19, 2022
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