Skip to content

gh-128923: fix test_pydoc for object subclasses without __module__ #128951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,8 @@ def makename(c, m=object.__module__):
# 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)
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_pydoc/test_pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,14 @@ class object
| ... 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"
Expand Down
Loading