Skip to content

Commit 0d207c3

Browse files
[3.12] gh-128772: Fix pydoc for methods with __module__ is None (GH-129177) (GH-129654)
(cherry picked from commit 979d766) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 676ee57 commit 0d207c3

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

Diff for: Lib/pydoc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def parentname(object, modname):
210210
if necessary) or module."""
211211
if '.' in object.__qualname__:
212212
name = object.__qualname__.rpartition('.')[0]
213-
if object.__module__ != modname:
213+
if object.__module__ != modname and object.__module__ is not None:
214214
return object.__module__ + '.' + name
215215
else:
216216
return name

Diff for: Lib/test/test_pydoc/module_none.py

+8
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

Diff for: Lib/test/test_pydoc/test_pydoc.py

+5
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,11 @@ def a_fn_with_https_link():
15921592
html
15931593
)
15941594

1595+
def test_module_none(self):
1596+
# Issue #128772
1597+
from test.test_pydoc import module_none
1598+
pydoc.render_doc(module_none)
1599+
15951600

15961601
class PydocFodderTest(unittest.TestCase):
15971602
def tearDown(self):
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)