]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-139076: Fix regression in pydoc not showing extension functions (GH-139077...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 19 Sep 2025 13:38:20 +0000 (15:38 +0200)
committerGitHub <noreply@github.com>
Fri, 19 Sep 2025 13:38:20 +0000 (16:38 +0300)
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 <storchaka@gmail.com>
Lib/pydoc.py
Lib/test/test_pydoc/pydocfodder.py
Lib/test/test_pydoc/test_pydoc.py
Misc/NEWS.d/next/Library/2025-09-17-21-54-53.gh-issue-139076.2eX9lG.rst [new file with mode: 0644]

index 00a65b2ded716ec6173431d0235d326a4903171d..94ada32f3d8628f77c3d1dcaff9fcfc97a188ad9 100755 (executable)
@@ -879,6 +879,7 @@ class HTMLDoc(Doc):
         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))
@@ -1323,6 +1324,7 @@ location listed above.
         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))
index 3cc2d5bd57fe5b30298673798760befd44264a38..412aa3743e430b35c08619e4e2170f31261168d8 100644 (file)
@@ -87,6 +87,8 @@ class B(A):
     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 @@ __repr__ = object.__repr__  # same name
 object_repr = object.__repr__
 get = {}.get  # same name
 dict_get = {}.get
+from math import sin  # noqa: F401
index 10cebfb2801495d3e894deb640eb978a24111763..e84bc48ff11f132b69c4d52a016ab13f12d80383 100644 (file)
@@ -1926,9 +1926,11 @@ class PydocFodderTest(unittest.TestCase):
         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)
@@ -2014,6 +2016,11 @@ class PydocFodderTest(unittest.TestCase):
             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()
@@ -2054,6 +2061,12 @@ class PydocFodderTest(unittest.TestCase):
             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_emscripten or is_wasi,
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 (file)
index 0000000..5e0ae6e
--- /dev/null
@@ -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__``.