https://github.com/python/cpython/commit/7eba097137a047d1ddbd6e052979b5babf264954
commit: 7eba097137a047d1ddbd6e052979b5babf264954
branch: 3.13
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: serhiy-storchaka <storch...@gmail.com>
date: 2025-02-05T14:42:51Z
summary:

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

(cherry picked from commit 979d76620990e6f8d68fa63e0ae0db1ec5b4d14c)

Co-authored-by: Serhiy Storchaka <storch...@gmail.com>

files:
A Lib/test/test_pydoc/module_none.py
A Misc/NEWS.d/next/Library/2025-01-22-13-29-06.gh-issue-128772.6YrxYM.rst
M Lib/pydoc.py
M Lib/test/test_pydoc/test_pydoc.py

diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 1a527b2c307b68..591d7bc8f865cf 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -242,7 +242,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
index 00000000000000..ebb50fc86e2cf7
--- /dev/null
+++ b/Lib/test/test_pydoc/module_none.py
@@ -0,0 +1,8 @@
+def func():
+    pass
+func.__module__ = None
+
+class A:
+    def method(self):
+        pass
+    method.__module__ = None
diff --git a/Lib/test/test_pydoc/test_pydoc.py 
b/Lib/test/test_pydoc/test_pydoc.py
index 9cc2252e29367d..00ec3cdb3d49e5 100644
--- a/Lib/test/test_pydoc/test_pydoc.py
+++ b/Lib/test/test_pydoc/test_pydoc.py
@@ -1875,6 +1875,11 @@ def a_fn_with_https_link():
             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
index 00000000000000..53d6b3ccaffda8
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-22-13-29-06.gh-issue-128772.6YrxYM.rst
@@ -0,0 +1,2 @@
+Fix :mod:`pydoc` for methods with the ``__module__`` attribute equal to
+``None``.

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to