Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-113942: Show functions implemented as builtin methods #115306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Lib/pydoc.py
Original file line number Diff line number Diff line change
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 @@ -1300,9 +1300,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/test_pydoc/pydocfodder.py
Original file line number Diff line number Diff line change
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/test_pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,8 @@ def test_text_doc_routines_in_class(self, cls=pydocfodder.B):
self.assertIn(' | global_func(x, y) from test.test_pydoc.pydocfodder', lines)
self.assertIn(' | global_func_alias = global_func(x, y)', lines)
self.assertIn(' | global_func2_alias = global_func2(x, y) from test.test_pydoc.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 @@ -1703,6 +1705,8 @@ def test_html_doc_routines_in_class(self, cls=pydocfodder.B):
self.assertIn('global_func(x, y) from test.test_pydoc.pydocfodder', lines)
self.assertIn('global_func_alias = global_func(x, y)', lines)
self.assertIn('global_func2_alias = global_func2(x, y) from test.test_pydoc.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 @@ -1746,6 +1750,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 @@ -1771,6 +1779,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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:mod:`pydoc` no longer skips global functions implemented as builtin methods,
such as :class:`~type.MethodDescriptorType` and :class:`~type.WrapperDescriptorType`.