Skip to content

Commit f9f97eb

Browse files
DOC: limit error traceback to one line for expected exceptions (GH10715)
1 parent f30e423 commit f9f97eb

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

doc/sphinxext/ipython_sphinxext/ipython_directive.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,6 @@ def process_input(self, data, input_prompt, lineno):
461461

462462
self.cout.seek(0)
463463
output = self.cout.read()
464-
if not is_suppress and not is_semicolon:
465-
ret.append(output)
466-
elif is_semicolon: # get spacing right
467-
ret.append('')
468464

469465
# context information
470466
filename = self.state.document.current_source
@@ -494,6 +490,16 @@ def process_input(self, data, input_prompt, lineno):
494490
sys.stdout.write(s)
495491
sys.stdout.write('<<<' + ('-' * 73) + '\n')
496492

493+
# if :okexcept: has been specified, display shorter traceback
494+
if is_okexcept and "Traceback" in output:
495+
traceback = output.split('\n\n')
496+
output = traceback[-1]
497+
498+
if not is_suppress and not is_semicolon:
499+
ret.append(output)
500+
elif is_semicolon: # get spacing right
501+
ret.append('')
502+
497503
self.cout.truncate(0)
498504
return (ret, input_lines, output, is_doctest, decorator, image_file,
499505
image_directive)

0 commit comments

Comments
 (0)