mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
[3.13] gh-120541: Improve the "less" prompt in pydoc (GH-120543) (GH-120562)
When help() is called with non-string argument, use __qualname__ or
__name__ if available, otherwise use "{typename} object".
(cherry picked from commit 31d1d72d7e
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
29bbd5f8e4
commit
3a9f438c92
3 changed files with 59 additions and 14 deletions
|
@ -1753,7 +1753,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