[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:
Miss Islington (bot) 2024-06-15 20:21:13 +02:00 committed by GitHub
parent 29bbd5f8e4
commit 3a9f438c92
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 59 additions and 14 deletions

View file

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