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

This commit is contained in:
Serhiy Storchaka 2024-07-23 20:45:21 +03:00 committed by GitHub
parent a15feded71
commit 4606eff0aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 3 deletions

View File

@ -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):

View File

@ -776,9 +776,16 @@ class PydocDocTest(unittest.TestCase):
'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',

View File

@ -0,0 +1 @@
Improve support of method descriptors and wrappers in the help title.