Skip to content

Commit 7eba097

Browse files
[3.13] gh-128772: Fix pydoc for methods with __module__ is None (GH-129177) (GH-129653)
(cherry picked from commit 979d766) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 19ceb34 commit 7eba097

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

Lib/pydoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def parentname(object, modname):
242242
if necessary) or module."""
243243
if '.' in object.__qualname__:
244244
name = object.__qualname__.rpartition('.')[0]
245-
if object.__module__ != modname:
245+
if object.__module__ != modname and object.__module__ is not None:
246246
return object.__module__ + '.' + name
247247
else:
248248
return name

Lib/test/test_pydoc/module_none.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def func():
2+
pass
3+
func.__module__ = None
4+
5+
class A:
6+
def method(self):
7+
pass
8+
method.__module__ = None

Lib/test/test_pydoc/test_pydoc.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,11 @@ def a_fn_with_https_link():
18751875
html
18761876
)
18771877

1878+
def test_module_none(self):
1879+
# Issue #128772
1880+
from test.test_pydoc import module_none
1881+
pydoc.render_doc(module_none)
1882+
18781883

18791884
class PydocFodderTest(unittest.TestCase):
18801885
def tearDown(self):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :mod:`pydoc` for methods with the ``__module__`` attribute equal to
2+
``None``.

0 commit comments

Comments
 (0)