]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-128772: Fix pydoc for methods with __module__ is None (GH-129177)
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 4 Feb 2025 14:25:49 +0000 (16:25 +0200)
committerGitHub <noreply@github.com>
Tue, 4 Feb 2025 14:25:49 +0000 (16:25 +0200)
Lib/pydoc.py
Lib/test/test_pydoc/module_none.py [new file with mode: 0644]
Lib/test/test_pydoc/test_pydoc.py
Misc/NEWS.d/next/Library/2025-01-22-13-29-06.gh-issue-128772.6YrxYM.rst [new file with mode: 0644]

index 922946e5fa7ddb1307d3fb7a86fac93249cc5ec2..1839b88fec28b139c2a37466fe47838ddb13cee3 100644 (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
diff --git a/Lib/test/test_pydoc/module_none.py b/Lib/test/test_pydoc/module_none.py
new file mode 100644 (file)
index 0000000..ebb50fc
--- /dev/null
@@ -0,0 +1,8 @@
+def func():
+    pass
+func.__module__ = None
+
+class A:
+    def method(self):
+        pass
+    method.__module__ = None
index b02ba3aafd4d20bcc6e773543b00890dade326e2..0abd36c5e076e266855b0d530141658ee840da08 100644 (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):
diff --git a/Misc/NEWS.d/next/Library/2025-01-22-13-29-06.gh-issue-128772.6YrxYM.rst b/Misc/NEWS.d/next/Library/2025-01-22-13-29-06.gh-issue-128772.6YrxYM.rst
new file mode 100644 (file)
index 0000000..53d6b3c
--- /dev/null
@@ -0,0 +1,2 @@
+Fix :mod:`pydoc` for methods with the ``__module__`` attribute equal to
+``None``.