https://github.com/python/cpython/commit/103766528fe9e678dd007474597b11156feaa7a6
commit: 103766528fe9e678dd007474597b11156feaa7a6
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: encukou <[email protected]>
date: 2025-10-07T21:57:28+02:00
summary:

[3.14] gh-139076: Fix regression in pydoc not showing extension functions 
(GH-139077) (GH-139160)

Fix a bug in the pydoc module that was hiding functions in a Python
module if they were implemented in an extension module and the module did
not have __all__.
(cherry picked from commit 7257b24140ac1b39fb8cfd4610134ec79575a396)

Co-authored-by: Serhiy Storchaka <[email protected]>

files:
A Misc/NEWS.d/next/Library/2025-09-17-21-54-53.gh-issue-139076.2eX9lG.rst
M Lib/pydoc.py
M Lib/test/test_pydoc/pydocfodder.py
M Lib/test/test_pydoc/test_pydoc.py

diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 7528178fdcae97..2a99fc40dda3fd 100644
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -884,6 +884,7 @@ def docmodule(self, object, name=None, mod=None, *ignored):
         for key, value in inspect.getmembers(object, inspect.isroutine):
             # if __all__ exists, believe it.  Otherwise use a heuristic.
             if (all is not None
+                or inspect.isbuiltin(value)
                 or (inspect.getmodule(value) or object) is object):
                 if visiblename(key, all, object):
                     funcs.append((key, value))
@@ -1328,6 +1329,7 @@ def docmodule(self, object, name=None, mod=None, 
*ignored):
         for key, value in inspect.getmembers(object, inspect.isroutine):
             # if __all__ exists, believe it.  Otherwise use a heuristic.
             if (all is not None
+                or inspect.isbuiltin(value)
                 or (inspect.getmodule(value) or object) is object):
                 if visiblename(key, all, object):
                     funcs.append((key, value))
diff --git a/Lib/test/test_pydoc/pydocfodder.py 
b/Lib/test/test_pydoc/pydocfodder.py
index 3cc2d5bd57fe5b..412aa3743e430b 100644
--- a/Lib/test/test_pydoc/pydocfodder.py
+++ b/Lib/test/test_pydoc/pydocfodder.py
@@ -87,6 +87,8 @@ def B_classmethod(cls, x):
     object_repr = object.__repr__
     get = {}.get  # same name
     dict_get = {}.get
+    from math import sin
+
 
 B.B_classmethod_ref = B.B_classmethod
 
@@ -186,3 +188,4 @@ def __call__(self, inst):
 object_repr = object.__repr__
 get = {}.get  # same name
 dict_get = {}.get
+from math import sin  # noqa: F401
diff --git a/Lib/test/test_pydoc/test_pydoc.py 
b/Lib/test/test_pydoc/test_pydoc.py
index 953cfe69f87cb8..fb0a8bb7b2339b 100644
--- a/Lib/test/test_pydoc/test_pydoc.py
+++ b/Lib/test/test_pydoc/test_pydoc.py
@@ -1939,9 +1939,11 @@ def test_text_doc_routines_in_class(self, 
cls=pydocfodder.B):
         if not support.MISSING_C_DOCSTRINGS:
             self.assertIn(' |  get(key, default=None, /) method of 
builtins.dict instance', lines)
             self.assertIn(' |  dict_get = get(key, default=None, /) method of 
builtins.dict instance', lines)
+            self.assertIn(' |  sin(x, /)', lines)
         else:
             self.assertIn(' |  get(...) method of builtins.dict instance', 
lines)
             self.assertIn(' |  dict_get = get(...) method of builtins.dict 
instance', lines)
+            self.assertIn(' |  sin(...)', lines)
 
         lines = self.getsection(result, f' |  Class methods {where}:', ' |  ' 
+ '-'*70)
         self.assertIn(' |  B_classmethod(x)', lines)
@@ -2027,6 +2029,11 @@ def test_text_doc_routines_in_module(self):
             self.assertIn('    __repr__(...) unbound builtins.object method', 
lines)
             self.assertIn('    object_repr = __repr__(...) unbound 
builtins.object method', lines)
 
+        # builtin functions
+        if not support.MISSING_C_DOCSTRINGS:
+            self.assertIn('    sin(x, /)', lines)
+        else:
+            self.assertIn('    sin(...)', lines)
 
     def test_html_doc_routines_in_module(self):
         doc = pydoc.HTMLDoc()
@@ -2067,6 +2074,12 @@ def test_html_doc_routines_in_module(self):
             self.assertIn(' __repr__(...) unbound builtins.object method', 
lines)
             self.assertIn(' object_repr = __repr__(...) unbound 
builtins.object method', lines)
 
+        # builtin functions
+        if not support.MISSING_C_DOCSTRINGS:
+            self.assertIn(' sin(x, /)', lines)
+        else:
+            self.assertIn(' sin(...)', lines)
+
 
 @unittest.skipIf(
     is_wasm32,
diff --git 
a/Misc/NEWS.d/next/Library/2025-09-17-21-54-53.gh-issue-139076.2eX9lG.rst 
b/Misc/NEWS.d/next/Library/2025-09-17-21-54-53.gh-issue-139076.2eX9lG.rst
new file mode 100644
index 00000000000000..5e0ae6ed73edd4
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-09-17-21-54-53.gh-issue-139076.2eX9lG.rst
@@ -0,0 +1,3 @@
+Fix a bug in the :mod:`pydoc` module that was hiding functions in a Python
+module if they were implemented in an extension module and the module did
+not have ``__all__``.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to