summaryrefslogtreecommitdiffstats
path: root/Lib/pydoc.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-06-15 17:56:40 (GMT)
committerGitHub <noreply@github.com>2024-06-15 17:56:40 (GMT)
commit31d1d72d7e24e0427df70f7dd14b9baff28a4f89 (patch)
tree6c0df87892247f1318e188a31620e7ed07a461e9 /Lib/pydoc.py
parent9e0b11eb21930b7b8e4a396200a921e9985cfca4 (diff)
downloadcpython-31d1d72d7e24e0427df70f7dd14b9baff28a4f89.zip
cpython-31d1d72d7e24e0427df70f7dd14b9baff28a4f89.tar.gz
cpython-31d1d72d7e24e0427df70f7dd14b9baff28a4f89.tar.bz2
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".
Diffstat (limited to 'Lib/pydoc.py')
-rw-r--r--Lib/pydoc.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index be5cd9a..768c3dc 100644
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -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: