]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-128772: Fix pydoc for methods with __module__ is None (GH-129177) (GH-129654)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 4 Feb 2025 14:44:02 +0000 (15:44 +0100)
committerGitHub <noreply@github.com>
Tue, 4 Feb 2025 14:44:02 +0000 (14:44 +0000)
(cherry picked from commit 979d76620990e6f8d68fa63e0ae0db1ec5b4d14c)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
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 9dfa87b2a8239582810482bdfe42ad38190f6b36..b58bcf0e22a6958cce51d40760980b9cf1fb70ef 100755 (executable)
@@ -210,7 +210,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 8261c8561a1d69f7641c47d85d7a6841f8b232c5..79f43abd6e4dca4af379d27d48cf488be33fd264 100644 (file)
@@ -1592,6 +1592,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``.