mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
gh-102541: Hide traceback in help prompt (gh-102614)
This commit is contained in:
parent
0316063031
commit
ba516e70c6
2 changed files with 14 additions and 8 deletions
21
Lib/pydoc.py
21
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)
|
return title % desc + '\n\n' + renderer.document(object, name)
|
||||||
|
|
||||||
def doc(thing, title='Python Library Documentation: %s', forceload=0,
|
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."""
|
"""Display text documentation, given an object or a path to an object."""
|
||||||
if output is None:
|
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:
|
else:
|
||||||
output.write(render_doc(thing, title, forceload, plaintext))
|
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()
|
self.output.flush()
|
||||||
return self.input.readline()
|
return self.input.readline()
|
||||||
|
|
||||||
def help(self, request):
|
def help(self, request, is_cli=False):
|
||||||
if isinstance(request, str):
|
if isinstance(request, str):
|
||||||
request = request.strip()
|
request = request.strip()
|
||||||
if request == 'keywords': self.listkeywords()
|
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 self.symbols: self.showsymbol(request)
|
||||||
elif request in ['True', 'False', 'None']:
|
elif request in ['True', 'False', 'None']:
|
||||||
# special case these keywords since they are objects too
|
# 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.keywords: self.showtopic(request)
|
||||||
elif request in self.topics: self.showtopic(request)
|
elif request in self.topics: self.showtopic(request)
|
||||||
elif request: doc(request, '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)
|
else: doc(str, 'Help on %s:', output=self._output, is_cli=is_cli)
|
||||||
elif isinstance(request, Helper): self()
|
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')
|
self.output.write('\n')
|
||||||
|
|
||||||
def intro(self):
|
def intro(self):
|
||||||
|
@ -2800,7 +2805,7 @@ def cli():
|
||||||
else:
|
else:
|
||||||
writedoc(arg)
|
writedoc(arg)
|
||||||
else:
|
else:
|
||||||
help.help(arg)
|
help.help(arg, is_cli=True)
|
||||||
except (ImportError, ErrorDuringImport) as value:
|
except (ImportError, ErrorDuringImport) as value:
|
||||||
print(value)
|
print(value)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Hide traceback in :func:`help` prompt, when import failed.
|
Loading…
Add table
Add a link
Reference in a new issue