summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKirill Podoprigora <kirill.bast9@mail.ru>2023-06-14 12:17:12 (GMT)
committerGitHub <noreply@github.com>2023-06-14 12:17:12 (GMT)
commitba516e70c6d156dc59dede35b6fc3db0151780a5 (patch)
treedb8093bb8feb2d99f111a10c48cea56866569b38
parent03160630319ca26dcbbad65225da4248e54c45ec (diff)
downloadcpython-ba516e70c6d156dc59dede35b6fc3db0151780a5.zip
cpython-ba516e70c6d156dc59dede35b6fc3db0151780a5.tar.gz
cpython-ba516e70c6d156dc59dede35b6fc3db0151780a5.tar.bz2
gh-102541: Hide traceback in help prompt (gh-102614)
-rwxr-xr-xLib/pydoc.py21
-rw-r--r--Misc/NEWS.d/next/Library/2023-03-12-01-17-15.gh-issue-102541.LK1adc.rst1
2 files changed, 14 insertions, 8 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 84e673a..d69369d 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -1780,10 +1780,15 @@ def render_doc(thing, title='Python Library Documentation: %s', forceload=0,
return title % desc + '\n\n' + renderer.document(object, name)
def doc(thing, title='Python Library Documentation: %s', forceload=0,
- output=None):
+ output=None, is_cli=False):
"""Display text documentation, given an object or a path to an object."""
if output is None:
- pager(render_doc(thing, title, forceload))
+ try:
+ pager(render_doc(thing, title, forceload))
+ except ImportError as exc:
+ if is_cli:
+ raise
+ print(exc)
else:
output.write(render_doc(thing, title, forceload, plaintext))
@@ -2044,7 +2049,7 @@ has the same effect as typing a particular string at the help> prompt.
self.output.flush()
return self.input.readline()
- def help(self, request):
+ def help(self, request, is_cli=False):
if isinstance(request, str):
request = request.strip()
if request == 'keywords': self.listkeywords()
@@ -2056,13 +2061,13 @@ has the same effect as typing a particular string at the help> prompt.
elif request in self.symbols: self.showsymbol(request)
elif request in ['True', 'False', 'None']:
# special case these keywords since they are objects too
- doc(eval(request), 'Help on %s:')
+ doc(eval(request), 'Help on %s:', is_cli=is_cli)
elif request in self.keywords: self.showtopic(request)
elif request in self.topics: self.showtopic(request)
- elif request: doc(request, 'Help on %s:', output=self._output)
- else: doc(str, 'Help on %s:', output=self._output)
+ elif request: doc(request, 'Help on %s:', output=self._output, is_cli=is_cli)
+ else: doc(str, 'Help on %s:', output=self._output, is_cli=is_cli)
elif isinstance(request, Helper): self()
- else: doc(request, 'Help on %s:', output=self._output)
+ else: doc(request, 'Help on %s:', output=self._output, is_cli=is_cli)
self.output.write('\n')
def intro(self):
@@ -2800,7 +2805,7 @@ def cli():
else:
writedoc(arg)
else:
- help.help(arg)
+ help.help(arg, is_cli=True)
except (ImportError, ErrorDuringImport) as value:
print(value)
sys.exit(1)
diff --git a/Misc/NEWS.d/next/Library/2023-03-12-01-17-15.gh-issue-102541.LK1adc.rst b/Misc/NEWS.d/next/Library/2023-03-12-01-17-15.gh-issue-102541.LK1adc.rst
new file mode 100644
index 0000000..45b1067
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-03-12-01-17-15.gh-issue-102541.LK1adc.rst
@@ -0,0 +1 @@
+Hide traceback in :func:`help` prompt, when import failed.