Fix pydoc's docclass() for classes inheriting from object without the `__module__` attribute, like `_testcapi.HeapType`.
# List the built-in subclasses, if any:
subclasses = sorted(
(str(cls.__name__) for cls in type.__subclasses__(object)
- if not cls.__name__.startswith("_") and cls.__module__ == "builtins"),
+ if (not cls.__name__.startswith("_") and
+ getattr(cls, '__module__', '') == "builtins")),
key=str.lower
)
no_of_subclasses = len(subclasses)
| ... and 82 other subclasses
"""
doc = pydoc.TextDoc()
+ try:
+ # Make sure HeapType, which has no __module__ attribute, is one
+ # of the known subclasses of object. (doc.docclass() used to
+ # fail if HeapType was imported before running this test, like
+ # when running tests sequentially.)
+ from _testcapi import HeapType
+ except ImportError:
+ pass
text = doc.docclass(object)
snip = (" | Built-in subclasses:\n"
" | async_generator\n"