Skip to content

Commit 7257b24

Browse files
gh-139076: Fix regression in pydoc not showing extension functions (GH-139077)
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__.
1 parent b36dee8 commit 7257b24

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
@@ -884,6 +884,7 @@ def docmodule(self, object, name=None, mod=None, *ignored):
884884
for key, value in inspect.getmembers(object, inspect.isroutine):
885885
# if __all__ exists, believe it. Otherwise use a heuristic.
886886
if (all is not None
887+
or inspect.isbuiltin(value)
887888
or (inspect.getmodule(value) or object) is object):
888889
if visiblename(key, all, object):
889890
funcs.append((key, value))
@@ -1328,6 +1329,7 @@ def docmodule(self, object, name=None, mod=None, *ignored):
13281329
for key, value in inspect.getmembers(object, inspect.isroutine):
13291330
# if __all__ exists, believe it. Otherwise use a heuristic.
13301331
if (all is not None
1332+
or inspect.isbuiltin(value)
13311333
or (inspect.getmodule(value) or object) is object):
13321334
if visiblename(key, all, object):
13331335
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
@@ -1951,9 +1951,11 @@ def test_text_doc_routines_in_class(self, cls=pydocfodder.B):
19511951
if not support.MISSING_C_DOCSTRINGS:
19521952
self.assertIn(' | get(key, default=None, /) method of builtins.dict instance', lines)
19531953
self.assertIn(' | dict_get = get(key, default=None, /) method of builtins.dict instance', lines)
1954+
self.assertIn(' | sin(x, /)', lines)
19541955
else:
19551956
self.assertIn(' | get(...) method of builtins.dict instance', lines)
19561957
self.assertIn(' | dict_get = get(...) method of builtins.dict instance', lines)
1958+
self.assertIn(' | sin(...)', lines)
19571959

19581960
lines = self.getsection(result, f' | Class methods {where}:', ' | ' + '-'*70)
19591961
self.assertIn(' | B_classmethod(x)', lines)
@@ -2039,6 +2041,11 @@ def test_text_doc_routines_in_module(self):
20392041
self.assertIn(' __repr__(...) unbound builtins.object method', lines)
20402042
self.assertIn(' object_repr = __repr__(...) unbound builtins.object method', lines)
20412043

2044+
# builtin functions
2045+
if not support.MISSING_C_DOCSTRINGS:
2046+
self.assertIn(' sin(x, /)', lines)
2047+
else:
2048+
self.assertIn(' sin(...)', lines)
20422049

20432050
def test_html_doc_routines_in_module(self):
20442051
doc = pydoc.HTMLDoc()
@@ -2079,6 +2086,12 @@ def test_html_doc_routines_in_module(self):
20792086
self.assertIn(' __repr__(...) unbound builtins.object method', lines)
20802087
self.assertIn(' object_repr = __repr__(...) unbound builtins.object method', lines)
20812088

2089+
# builtin functions
2090+
if not support.MISSING_C_DOCSTRINGS:
2091+
self.assertIn(' sin(x, /)', lines)
2092+
else:
2093+
self.assertIn(' sin(...)', lines)
2094+
20822095

20832096
@unittest.skipIf(
20842097
is_wasm32,
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)