MCPcopy Create free account
hub / github.com/ipython/ipython / tb

Method tb

IPython/core/magics/execution.py:494–523  ·  view source on GitHub ↗

Print the last traceback. Optionally, specify an exception reporting mode, tuning the verbosity of the traceback. By default the currently-active exception mode is used. See %xmode for changing exception reporting modes. Valid modes: Plain, Context, Verbose, and Min

(self, s)

Source from the content-addressed store, hash-verified

492
493 @line_magic
494 def tb(self, s):
495 """Print the last traceback.
496
497 Optionally, specify an exception reporting mode, tuning the
498 verbosity of the traceback. By default the currently-active exception
499 mode is used. See %xmode for changing exception reporting modes.
500
501 Valid modes: Plain, Context, Verbose, and Minimal.
502 """
503 interactive_tb = self.shell.InteractiveTB
504 if s:
505 # Switch exception reporting mode for this one call.
506 # Ensure it is switched back.
507 def xmode_switch_err(name):
508 warn('Error changing %s exception modes.\n%s' %
509 (name,sys.exc_info()[1]))
510
511 new_mode = s.strip().capitalize()
512 original_mode = interactive_tb.mode
513 try:
514 try:
515 interactive_tb.set_mode(mode=new_mode)
516 except Exception:
517 xmode_switch_err('user')
518 else:
519 self.shell.showtraceback()
520 finally:
521 interactive_tb.set_mode(mode=original_mode)
522 else:
523 self.shell.showtraceback()
524
525 @skip_doctest
526 @line_magic

Callers

nothing calls this directly

Calls 2

set_modeMethod · 0.80
showtracebackMethod · 0.80

Tested by

no test coverage detected