gh-128772: Fix pydoc for methods with __module__ is None (GH-129177)

This commit is contained in:
Serhiy Storchaka 2025-02-04 16:25:49 +02:00 committed by GitHub
parent 8b5c8508c7
commit 979d766209
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 1 deletions

View file

@ -245,7 +245,7 @@ def parentname(object, modname):
if necessary) or module."""
if '.' in object.__qualname__:
name = object.__qualname__.rpartition('.')[0]
if object.__module__ != modname:
if object.__module__ != modname and object.__module__ is not None:
return object.__module__ + '.' + name
else:
return name

View file

@ -0,0 +1,8 @@
def func():
pass
func.__module__ = None
class A:
def method(self):
pass
method.__module__ = None

View file

@ -1903,6 +1903,11 @@ foo
html
)
def test_module_none(self):
# Issue #128772
from test.test_pydoc import module_none
pydoc.render_doc(module_none)
class PydocFodderTest(unittest.TestCase):
def tearDown(self):

View file

@ -0,0 +1,2 @@
Fix :mod:`pydoc` for methods with the ``__module__`` attribute equal to
``None``.