https://github.com/python/cpython/commit/4606eff0aa01d6ce30d25b05ed347567ea59b00b
commit: 4606eff0aa01d6ce30d25b05ed347567ea59b00b
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2024-07-23T20:45:21+03:00
summary:

gh-122129: Improve support of method descriptors and wrappers in the help title 
(GH-122157)

files:
A Misc/NEWS.d/next/Library/2024-07-23-13-07-12.gh-issue-122129.PwbC8q.rst
M Lib/pydoc.py
M Lib/test/test_pydoc/test_pydoc.py

diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 768c3dcb11ec59..d376592d69d40d 100644
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -1682,6 +1682,13 @@ def describe(thing):
         return 'function ' + thing.__name__
     if inspect.ismethod(thing):
         return 'method ' + thing.__name__
+    if inspect.ismethodwrapper(thing):
+        return 'method wrapper ' + thing.__name__
+    if inspect.ismethoddescriptor(thing):
+        try:
+            return 'method descriptor ' + thing.__name__
+        except AttributeError:
+            pass
     return type(thing).__name__
 
 def locate(path, forceload=0):
diff --git a/Lib/test/test_pydoc/test_pydoc.py 
b/Lib/test/test_pydoc/test_pydoc.py
index 40b3aca25e0da8..2dba077cdea6a7 100644
--- a/Lib/test/test_pydoc/test_pydoc.py
+++ b/Lib/test/test_pydoc/test_pydoc.py
@@ -776,9 +776,16 @@ def run_pydoc_pager(request, what, expected_first_line):
                         'Help on function help in module pydoc:')
         run_pydoc_pager('str', 'str', 'Help on class str in module builtins:')
         run_pydoc_pager(str, 'str', 'Help on class str in module builtins:')
-        run_pydoc_pager('str.upper', 'str.upper', 'Help on method_descriptor 
in str:')
-        run_pydoc_pager(str.upper, 'str.upper', 'Help on method_descriptor:')
-        run_pydoc_pager(str.__add__, 'str.__add__', 'Help on 
wrapper_descriptor:')
+        run_pydoc_pager('str.upper', 'str.upper',
+                        'Help on method descriptor upper in str:')
+        run_pydoc_pager(str.upper, 'str.upper',
+                        'Help on method descriptor upper:')
+        run_pydoc_pager(''.upper, 'str.upper',
+                        'Help on built-in function upper:')
+        run_pydoc_pager(str.__add__,
+                        'str.__add__', 'Help on method descriptor __add__:')
+        run_pydoc_pager(''.__add__,
+                        'str.__add__', 'Help on method wrapper __add__:')
         run_pydoc_pager(int.numerator, 'int.numerator',
                         'Help on getset descriptor builtins.int.numerator:')
         run_pydoc_pager(list[int], 'list',
diff --git 
a/Misc/NEWS.d/next/Library/2024-07-23-13-07-12.gh-issue-122129.PwbC8q.rst 
b/Misc/NEWS.d/next/Library/2024-07-23-13-07-12.gh-issue-122129.PwbC8q.rst
new file mode 100644
index 00000000000000..08beb45653d24b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-07-23-13-07-12.gh-issue-122129.PwbC8q.rst
@@ -0,0 +1 @@
+Improve support of method descriptors and wrappers in the help title.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to