Skip to content

Commit

Permalink
pythongh-113942: Show functions implemented as builtin methods
Browse files Browse the repository at this point in the history
Pydoc no longer skips global functions implemented as builtin methods,
such as MethodDescriptorType and WrapperDescriptorType.
  • Loading branch information
serhiy-storchaka committed Feb 11, 2024
1 parent 2939ad0 commit 3713125
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Lib/pydoc.py
Expand Up @@ -856,9 +856,9 @@ def docmodule(self, object, name=None, mod=None, *ignored):
cdict[key] = cdict[base] = modname + '.html#' + key
funcs, fdict = [], {}
for key, value in inspect.getmembers(object, inspect.isroutine):
# if __all__ exists, believe it. Otherwise use old heuristic.
if (all is not None or
inspect.isbuiltin(value) or inspect.getmodule(value) is object):
# if __all__ exists, believe it. Otherwise use a heuristic.
if (all is not None
or (inspect.getmodule(value) or object) is object):
if visiblename(key, all, object):
funcs.append((key, value))
fdict[key] = '#-' + key
Expand Down Expand Up @@ -1299,9 +1299,9 @@ def docmodule(self, object, name=None, mod=None, *ignored):
classes.append((key, value))
funcs = []
for key, value in inspect.getmembers(object, inspect.isroutine):
# if __all__ exists, believe it. Otherwise use old heuristic.
if (all is not None or
inspect.isbuiltin(value) or inspect.getmodule(value) is object):
# if __all__ exists, believe it. Otherwise use a heuristic.
if (all is not None
or (inspect.getmodule(value) or object) is object):
if visiblename(key, all, object):
funcs.append((key, value))
data = []
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/pydocfodder.py
Expand Up @@ -81,6 +81,8 @@ def B_classmethod(cls, x):
A_method_ref = A().A_method
A_method_alias = A.A_method
B_method_alias = B_method
count = list.count # same name
list_count = list.count
__repr__ = object.__repr__ # same name
object_repr = object.__repr__
get = {}.get # same name
Expand Down Expand Up @@ -180,5 +182,7 @@ def __call__(self, inst):
B_method2 = B.B_method
count = list.count # same name
list_count = list.count
__repr__ = object.__repr__ # same name
object_repr = object.__repr__
get = {}.get # same name
dict_get = {}.get
12 changes: 12 additions & 0 deletions Lib/test/test_pydoc.py
Expand Up @@ -1652,6 +1652,8 @@ def test_text_doc_routines_in_class(self, cls=pydocfodder.B):
self.assertIn(' | global_func(x, y) from test.pydocfodder', lines)
self.assertIn(' | global_func_alias = global_func(x, y)', lines)
self.assertIn(' | global_func2_alias = global_func2(x, y) from test.pydocfodder', lines)
self.assertIn(' | count(self, value, /) from builtins.list', lines)
self.assertIn(' | list_count = count(self, value, /)', lines)
self.assertIn(' | __repr__(self, /) from builtins.object', lines)
self.assertIn(' | object_repr = __repr__(self, /)', lines)

Expand Down Expand Up @@ -1680,6 +1682,8 @@ def test_html_doc_routines_in_class(self, cls=pydocfodder.B):
self.assertIn('global_func(x, y) from test.pydocfodder', lines)
self.assertIn('global_func_alias = global_func(x, y)', lines)
self.assertIn('global_func2_alias = global_func2(x, y) from test.pydocfodder', lines)
self.assertIn('count(self, value, /) from builtins.list', lines)
self.assertIn('list_count = count(self, value, /)', lines)
self.assertIn('__repr__(self, /) from builtins.object', lines)
self.assertIn('object_repr = __repr__(self, /)', lines)

Expand Down Expand Up @@ -1723,6 +1727,10 @@ def test_text_doc_routines_in_module(self):
# unbound methods
self.assertIn(' B_method(self)', lines)
self.assertIn(' B_method2 = B_method(self)', lines)
self.assertIn(' count(self, value, /) unbound builtins.list method', lines)
self.assertIn(' list_count = count(self, value, /) unbound builtins.list method', lines)
self.assertIn(' __repr__(self, /) unbound builtins.object method', lines)
self.assertIn(' object_repr = __repr__(self, /) unbound builtins.object method', lines)

def test_html_doc_routines_in_module(self):
doc = pydoc.HTMLDoc()
Expand All @@ -1748,6 +1756,10 @@ def test_html_doc_routines_in_module(self):
# unbound methods
self.assertIn(' B_method(self)', lines)
self.assertIn(' B_method2 = B_method(self)', lines)
self.assertIn(' count(self, value, /) unbound builtins.list method', lines)
self.assertIn(' list_count = count(self, value, /) unbound builtins.list method', lines)
self.assertIn(' __repr__(self, /) unbound builtins.object method', lines)
self.assertIn(' object_repr = __repr__(self, /) unbound builtins.object method', lines)


@unittest.skipIf(
Expand Down
@@ -0,0 +1,2 @@
:mod:`pydoc` no longer skips global functions implemented as builtin methods,
such as :class:`~type.MethodDescriptorType` and :class:`~type.WrapperDescriptorType`.

0 comments on commit 3713125

Please sign in to comment.