summaryrefslogtreecommitdiffstats
path: root/Lib/pydoc.py
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na@python.org>2023-06-15 15:29:00 (GMT)
committerGitHub <noreply@github.com>2023-06-15 15:29:00 (GMT)
commitabeb589290ef6458974d65a3f98e52d1f6bb9d49 (patch)
tree53a8034dd618e7dd4489b3bd6b8cd92096e7312d /Lib/pydoc.py
parent6be46c37c6c2a3f26f51141994bac0f4baf809b5 (diff)
downloadcpython-abeb589290ef6458974d65a3f98e52d1f6bb9d49.zip
cpython-abeb589290ef6458974d65a3f98e52d1f6bb9d49.tar.gz
cpython-abeb589290ef6458974d65a3f98e52d1f6bb9d49.tar.bz2
[3.11] gh-102541: Hide traceback in help prompt (gh-102614). (gh-105830)
(cherry picked from commit ba516e70c6d156dc59dede35b6fc3db0151780a5) Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-xLib/pydoc.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 088a3ba..151c7e8 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -1778,10 +1778,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))
@@ -2042,8 +2047,8 @@ has the same effect as typing a particular string at the help> prompt.
self.output.flush()
return self.input.readline()
- def help(self, request):
- if type(request) is type(''):
+ def help(self, request, is_cli=False):
+ if isinstance(request, str):
request = request.strip()
if request == 'keywords': self.listkeywords()
elif request == 'symbols': self.listsymbols()
@@ -2054,13 +2059,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):
@@ -2798,7 +2803,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)