Skip to content

Commit 9809c30

Browse files
[3.13] gh-139076: Fix regression in pydoc not showing extension functions (GH-139077) (GH-139161)
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 7257b24) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 8246e25 commit 9809c30

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

Lib/pydoc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ def docmodule(self, object, name=None, mod=None, *ignored):
879879
for key, value in inspect.getmembers(object, inspect.isroutine):
880880
# if __all__ exists, believe it. Otherwise use a heuristic.
881881
if (all is not None
882+
or inspect.isbuiltin(value)
882883
or (inspect.getmodule(value) or object) is object):
883884
if visiblename(key, all, object):
884885
funcs.append((key, value))
@@ -1323,6 +1324,7 @@ def docmodule(self, object, name=None, mod=None, *ignored):
13231324
for key, value in inspect.getmembers(object, inspect.isroutine):
13241325
# if __all__ exists, believe it. Otherwise use a heuristic.
13251326
if (all is not None
1327+
or inspect.isbuiltin(value)
13261328
or (inspect.getmodule(value) or object) is object):
13271329
if visiblename(key, all, object):
13281330
funcs.append((key, value))

Lib/test/test_pydoc/pydocfodder.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def B_classmethod(cls, x):
8787
object_repr = object.__repr__
8888
get = {}.get # same name
8989
dict_get = {}.get
90+
from math import sin
91+
9092

9193
B.B_classmethod_ref = B.B_classmethod
9294

@@ -186,3 +188,4 @@ def __call__(self, inst):
186188
object_repr = object.__repr__
187189
get = {}.get # same name
188190
dict_get = {}.get
191+
from math import sin # noqa: F401

Lib/test/test_pydoc/test_pydoc.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,9 +1926,11 @@ def test_text_doc_routines_in_class(self, cls=pydocfodder.B):
19261926
if not support.MISSING_C_DOCSTRINGS:
19271927
self.assertIn(' | get(key, default=None, /) method of builtins.dict instance', lines)
19281928
self.assertIn(' | dict_get = get(key, default=None, /) method of builtins.dict instance', lines)
1929+
self.assertIn(' | sin(x, /)', lines)
19291930
else:
19301931
self.assertIn(' | get(...) method of builtins.dict instance', lines)
19311932
self.assertIn(' | dict_get = get(...) method of builtins.dict instance', lines)
1933+
self.assertIn(' | sin(...)', lines)
19321934

19331935
lines = self.getsection(result, f' | Class methods {where}:', ' | ' + '-'*70)
19341936
self.assertIn(' | B_classmethod(x)', lines)
@@ -2014,6 +2016,11 @@ def test_text_doc_routines_in_module(self):
20142016
self.assertIn(' __repr__(...) unbound builtins.object method', lines)
20152017
self.assertIn(' object_repr = __repr__(...) unbound builtins.object method', lines)
20162018

2019+
# builtin functions
2020+
if not support.MISSING_C_DOCSTRINGS:
2021+
self.assertIn(' sin(x, /)', lines)
2022+
else:
2023+
self.assertIn(' sin(...)', lines)
20172024

20182025
def test_html_doc_routines_in_module(self):
20192026
doc = pydoc.HTMLDoc()
@@ -2054,6 +2061,12 @@ def test_html_doc_routines_in_module(self):
20542061
self.assertIn(' __repr__(...) unbound builtins.object method', lines)
20552062
self.assertIn(' object_repr = __repr__(...) unbound builtins.object method', lines)
20562063

2064+
# builtin functions
2065+
if not support.MISSING_C_DOCSTRINGS:
2066+
self.assertIn(' sin(x, /)', lines)
2067+
else:
2068+
self.assertIn(' sin(...)', lines)
2069+
20572070

20582071
@unittest.skipIf(
20592072
is_emscripten or is_wasi,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a bug in the :mod:`pydoc` module that was hiding functions in a Python
2+
module if they were implemented in an extension module and the module did
3+
not have ``__all__``.

0 commit comments

Comments
 (0)