Skip to content
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

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

Merged
merged 1 commit into from
Jul 23, 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
7 changes: 7 additions & 0 deletions Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
picnixz marked this conversation as resolved.
Show resolved Hide resolved
except AttributeError:
pass
return type(thing).__name__

def locate(path, forceload=0):
Expand Down
13 changes: 10 additions & 3 deletions Lib/test/test_pydoc/test_pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve support of method descriptors and wrappers in the help title.
Loading