Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d4544cb

Browse filesBrowse files
authored
gh-128923: fix test_pydoc for object subclasses without __module__ (#128951)
Fix pydoc's docclass() for classes inheriting from object without the `__module__` attribute, like `_testcapi.HeapType`.
1 parent 13c4def commit d4544cb
Copy full SHA for d4544cb

File tree

Expand file treeCollapse file tree

2 files changed

+10
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-1
lines changed

‎Lib/pydoc.py

Copy file name to clipboardExpand all lines: Lib/pydoc.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,8 @@ def makename(c, m=object.__module__):
14351435
# List the built-in subclasses, if any:
14361436
subclasses = sorted(
14371437
(str(cls.__name__) for cls in type.__subclasses__(object)
1438-
if not cls.__name__.startswith("_") and cls.__module__ == "builtins"),
1438+
if (not cls.__name__.startswith("_") and
1439+
getattr(cls, '__module__', '') == "builtins")),
14391440
key=str.lower
14401441
)
14411442
no_of_subclasses = len(subclasses)

‎Lib/test/test_pydoc/test_pydoc.py

Copy file name to clipboardExpand all lines: Lib/test/test_pydoc/test_pydoc.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,14 @@ class object
556556
| ... and 82 other subclasses
557557
"""
558558
doc = pydoc.TextDoc()
559+
try:
560+
# Make sure HeapType, which has no __module__ attribute, is one
561+
# of the known subclasses of object. (doc.docclass() used to
562+
# fail if HeapType was imported before running this test, like
563+
# when running tests sequentially.)
564+
from _testcapi import HeapType
565+
except ImportError:
566+
pass
559567
text = doc.docclass(object)
560568
snip = (" | Built-in subclasses:\n"
561569
" | async_generator\n"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.