Skip to content

Commit 72cff8d

Browse files
gh-113942: Show functions implemented as builtin methods (GH-115306)
Pydoc no longer skips global functions implemented as builtin methods, such as MethodDescriptorType and WrapperDescriptorType.
1 parent 68c79d2 commit 72cff8d

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

Lib/pydoc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -855,9 +855,9 @@ def docmodule(self, object, name=None, mod=None, *ignored):
855855
cdict[key] = cdict[base] = modname + '.html#' + key
856856
funcs, fdict = [], {}
857857
for key, value in inspect.getmembers(object, inspect.isroutine):
858-
# if __all__ exists, believe it. Otherwise use old heuristic.
859-
if (all is not None or
860-
inspect.isbuiltin(value) or inspect.getmodule(value) is object):
858+
# if __all__ exists, believe it. Otherwise use a heuristic.
859+
if (all is not None
860+
or (inspect.getmodule(value) or object) is object):
861861
if visiblename(key, all, object):
862862
funcs.append((key, value))
863863
fdict[key] = '#-' + key
@@ -1299,9 +1299,9 @@ def docmodule(self, object, name=None, mod=None, *ignored):
12991299
classes.append((key, value))
13001300
funcs = []
13011301
for key, value in inspect.getmembers(object, inspect.isroutine):
1302-
# if __all__ exists, believe it. Otherwise use old heuristic.
1303-
if (all is not None or
1304-
inspect.isbuiltin(value) or inspect.getmodule(value) is object):
1302+
# if __all__ exists, believe it. Otherwise use a heuristic.
1303+
if (all is not None
1304+
or (inspect.getmodule(value) or object) is object):
13051305
if visiblename(key, all, object):
13061306
funcs.append((key, value))
13071307
data = []

Lib/test/test_pydoc/pydocfodder.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def B_classmethod(cls, x):
8181
A_method_ref = A().A_method
8282
A_method_alias = A.A_method
8383
B_method_alias = B_method
84+
count = list.count # same name
85+
list_count = list.count
8486
__repr__ = object.__repr__ # same name
8587
object_repr = object.__repr__
8688
get = {}.get # same name
@@ -180,5 +182,7 @@ def __call__(self, inst):
180182
B_method2 = B.B_method
181183
count = list.count # same name
182184
list_count = list.count
185+
__repr__ = object.__repr__ # same name
186+
object_repr = object.__repr__
183187
get = {}.get # same name
184188
dict_get = {}.get

Lib/test/test_pydoc/test_pydoc.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,8 @@ def test_text_doc_routines_in_class(self, cls=pydocfodder.B):
16861686
self.assertIn(' | global_func(x, y) from test.test_pydoc.pydocfodder', lines)
16871687
self.assertIn(' | global_func_alias = global_func(x, y)', lines)
16881688
self.assertIn(' | global_func2_alias = global_func2(x, y) from test.test_pydoc.pydocfodder', lines)
1689+
self.assertIn(' | count(self, value, /) from builtins.list', lines)
1690+
self.assertIn(' | list_count = count(self, value, /)', lines)
16891691
self.assertIn(' | __repr__(self, /) from builtins.object', lines)
16901692
self.assertIn(' | object_repr = __repr__(self, /)', lines)
16911693

@@ -1714,6 +1716,8 @@ def test_html_doc_routines_in_class(self, cls=pydocfodder.B):
17141716
self.assertIn('global_func(x, y) from test.test_pydoc.pydocfodder', lines)
17151717
self.assertIn('global_func_alias = global_func(x, y)', lines)
17161718
self.assertIn('global_func2_alias = global_func2(x, y) from test.test_pydoc.pydocfodder', lines)
1719+
self.assertIn('count(self, value, /) from builtins.list', lines)
1720+
self.assertIn('list_count = count(self, value, /)', lines)
17171721
self.assertIn('__repr__(self, /) from builtins.object', lines)
17181722
self.assertIn('object_repr = __repr__(self, /)', lines)
17191723

@@ -1757,6 +1761,10 @@ def test_text_doc_routines_in_module(self):
17571761
# unbound methods
17581762
self.assertIn(' B_method(self)', lines)
17591763
self.assertIn(' B_method2 = B_method(self)', lines)
1764+
self.assertIn(' count(self, value, /) unbound builtins.list method', lines)
1765+
self.assertIn(' list_count = count(self, value, /) unbound builtins.list method', lines)
1766+
self.assertIn(' __repr__(self, /) unbound builtins.object method', lines)
1767+
self.assertIn(' object_repr = __repr__(self, /) unbound builtins.object method', lines)
17601768

17611769
def test_html_doc_routines_in_module(self):
17621770
doc = pydoc.HTMLDoc()
@@ -1782,6 +1790,10 @@ def test_html_doc_routines_in_module(self):
17821790
# unbound methods
17831791
self.assertIn(' B_method(self)', lines)
17841792
self.assertIn(' B_method2 = B_method(self)', lines)
1793+
self.assertIn(' count(self, value, /) unbound builtins.list method', lines)
1794+
self.assertIn(' list_count = count(self, value, /) unbound builtins.list method', lines)
1795+
self.assertIn(' __repr__(self, /) unbound builtins.object method', lines)
1796+
self.assertIn(' object_repr = __repr__(self, /) unbound builtins.object method', lines)
17851797

17861798

17871799
@unittest.skipIf(
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`pydoc` no longer skips global functions implemented as builtin methods,
2+
such as :class:`~type.MethodDescriptorType` and :class:`~type.WrapperDescriptorType`.

0 commit comments

Comments
 (0)