mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-120541: Improve the "less" prompt in pydoc (GH-120543)
When help() is called with non-string argument, use __qualname__ or __name__ if available, otherwise use "{typename} object".
This commit is contained in:
parent
9e0b11eb21
commit
31d1d72d7e
3 changed files with 59 additions and 14 deletions
|
@ -1755,7 +1755,14 @@ def doc(thing, title='Python Library Documentation: %s', forceload=0,
|
|||
"""Display text documentation, given an object or a path to an object."""
|
||||
if output is None:
|
||||
try:
|
||||
what = thing if isinstance(thing, str) else type(thing).__name__
|
||||
if isinstance(thing, str):
|
||||
what = thing
|
||||
else:
|
||||
what = getattr(thing, '__qualname__', None)
|
||||
if not isinstance(what, str):
|
||||
what = getattr(thing, '__name__', None)
|
||||
if not isinstance(what, str):
|
||||
what = type(thing).__name__ + ' object'
|
||||
pager(render_doc(thing, title, forceload), f'Help on {what!s}')
|
||||
except ImportError as exc:
|
||||
if is_cli:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue