summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-02-26 18:29:49 (GMT)
committerGitHub <noreply@github.com>2024-02-26 18:29:49 (GMT)
commit72cff8d8e5a476d3406efb0491452bf9d6b02feb (patch)
tree401a6020466917aa98fb0ade7e0d0686ea2c7702
parent68c79d21fa791d7418a858b7aa4604880e988a02 (diff)
downloadcpython-72cff8d8e5a476d3406efb0491452bf9d6b02feb.zip
cpython-72cff8d8e5a476d3406efb0491452bf9d6b02feb.tar.gz
cpython-72cff8d8e5a476d3406efb0491452bf9d6b02feb.tar.bz2
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.
-rwxr-xr-xLib/pydoc.py12
-rw-r--r--Lib/test/test_pydoc/pydocfodder.py4
-rw-r--r--Lib/test/test_pydoc/test_pydoc.py12
-rw-r--r--Misc/NEWS.d/next/Library/2024-02-11-20-12-39.gh-issue-113942.i72sMJ.rst2
4 files changed, 24 insertions, 6 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index d32fa8d..b0193b4 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -855,9 +855,9 @@ class HTMLDoc(Doc):
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
@@ -1299,9 +1299,9 @@ location listed above.
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 = []
diff --git a/Lib/test/test_pydoc/pydocfodder.py b/Lib/test/test_pydoc/pydocfodder.py
index 27037e0..3cc2d5b 100644
--- a/Lib/test/test_pydoc/pydocfodder.py
+++ b/Lib/test/test_pydoc/pydocfodder.py
@@ -81,6 +81,8 @@ class B(A):
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
@@ -180,5 +182,7 @@ B_method = B.B_method # same name
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
diff --git a/Lib/test/test_pydoc/test_pydoc.py b/Lib/test/test_pydoc/test_pydoc.py
index b07d911..9d40234 100644
--- a/Lib/test/test_pydoc/test_pydoc.py
+++ b/Lib/test/test_pydoc/test_pydoc.py
@@ -1686,6 +1686,8 @@ class PydocFodderTest(unittest.TestCase):
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)
@@ -1714,6 +1716,8 @@ class PydocFodderTest(unittest.TestCase):
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)
@@ -1757,6 +1761,10 @@ class PydocFodderTest(unittest.TestCase):
# 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()
@@ -1782,6 +1790,10 @@ class PydocFodderTest(unittest.TestCase):
# 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(
diff --git a/Misc/NEWS.d/next/Library/2024-02-11-20-12-39.gh-issue-113942.i72sMJ.rst b/Misc/NEWS.d/next/Library/2024-02-11-20-12-39.gh-issue-113942.i72sMJ.rst
new file mode 100644
index 0000000..2da43a4
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-02-11-20-12-39.gh-issue-113942.i72sMJ.rst
@@ -0,0 +1,2 @@
+:mod:`pydoc` no longer skips global functions implemented as builtin methods,
+such as :class:`~type.MethodDescriptorType` and :class:`~type.WrapperDescriptorType`.