Skip to content

Commit 1037665

Browse files
[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 7257b24) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent b53f46a commit 1037665

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
@@ -1939,9 +1939,11 @@ def test_text_doc_routines_in_class(self, cls=pydocfodder.B):
19391939
if not support.MISSING_C_DOCSTRINGS:
19401940
self.assertIn(' | get(key, default=None, /) method of builtins.dict instance', lines)
19411941
self.assertIn(' | dict_get = get(key, default=None, /) method of builtins.dict instance', lines)
1942+
self.assertIn(' | sin(x, /)', lines)
19421943
else:
19431944
self.assertIn(' | get(...) method of builtins.dict instance', lines)
19441945
self.assertIn(' | dict_get = get(...) method of builtins.dict instance', lines)
1946+
self.assertIn(' | sin(...)', lines)
19451947

19461948
lines = self.getsection(result, f' | Class methods {where}:', ' | ' + '-'*70)
19471949
self.assertIn(' | B_classmethod(x)', lines)
@@ -2027,6 +2029,11 @@ def test_text_doc_routines_in_module(self):
20272029
self.assertIn(' __repr__(...) unbound builtins.object method', lines)
20282030
self.assertIn(' object_repr = __repr__(...) unbound builtins.object method', lines)
20292031

2032+
# builtin functions
2033+
if not support.MISSING_C_DOCSTRINGS:
2034+
self.assertIn(' sin(x, /)', lines)
2035+
else:
2036+
self.assertIn(' sin(...)', lines)
20302037

20312038
def test_html_doc_routines_in_module(self):
20322039
doc = pydoc.HTMLDoc()
@@ -2067,6 +2074,12 @@ def test_html_doc_routines_in_module(self):
20672074
self.assertIn(' __repr__(...) unbound builtins.object method', lines)
20682075
self.assertIn(' object_repr = __repr__(...) unbound builtins.object method', lines)
20692076

2077+
# builtin functions
2078+
if not support.MISSING_C_DOCSTRINGS:
2079+
self.assertIn(' sin(x, /)', lines)
2080+
else:
2081+
self.assertIn(' sin(...)', lines)
2082+
20702083

20712084
@unittest.skipIf(
20722085
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)