diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index de4a262..ac46abe 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -580,7 +580,7 @@ class InteractiveShell(SingletonConfigurable): separate_out = SeparateUnicode('').tag(config=True) separate_out2 = SeparateUnicode('').tag(config=True) wildcards_case_sensitive = Bool(True).tag(config=True) - xmode = CaselessStrEnum(('Context','Plain', 'Verbose'), + xmode = CaselessStrEnum(('Context', 'Plain', 'Verbose', 'Minimal'), default_value='Context', help="Switch modes for the IPython exception handlers." ).tag(config=True) @@ -1788,7 +1788,7 @@ class InteractiveShell(SingletonConfigurable): # The interactive one is initialized with an offset, meaning we always # want to remove the topmost item in the traceback, which is our own - # internal code. Valid modes: ['Plain','Context','Verbose'] + # internal code. Valid modes: ['Plain','Context','Verbose','Minimal'] self.InteractiveTB = ultratb.AutoFormattedTB(mode = 'Plain', color_scheme='NoColor', tb_offset = 1, diff --git a/IPython/core/magics/basic.py b/IPython/core/magics/basic.py index 6a557fc..225c49a 100644 --- a/IPython/core/magics/basic.py +++ b/IPython/core/magics/basic.py @@ -363,7 +363,7 @@ Currently the magic system has the following functions:""", def xmode(self, parameter_s=''): """Switch modes for the exception handlers. - Valid modes: Plain, Context and Verbose. + Valid modes: Plain, Context, Verbose, and Minimal. If called without arguments, acts as a toggle.""" diff --git a/IPython/core/tests/test_ultratb.py b/IPython/core/tests/test_ultratb.py index fb6898f..8a96b8a 100644 --- a/IPython/core/tests/test_ultratb.py +++ b/IPython/core/tests/test_ultratb.py @@ -111,6 +111,9 @@ class NonAsciiTest(unittest.TestCase): with tt.AssertPrints(expected): ip.run_cell(cell) + ip.run_cell("%xmode minimal") + with tt.AssertPrints(u"Exception: é"): + ip.run_cell(cell) class NestedGenExprTestCase(unittest.TestCase): """ diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py index 78a4b3b..3060be1 100644 --- a/IPython/core/ultratb.py +++ b/IPython/core/ultratb.py @@ -1251,7 +1251,7 @@ class FormattedTB(VerboseTB, ListTB): parent=None, config=None): # NEVER change the order of this list. Put new modes at the end: - self.valid_modes = ['Plain', 'Context', 'Verbose'] + self.valid_modes = ['Plain', 'Context', 'Verbose', 'Minimal'] self.verbose_modes = self.valid_modes[1:3] VerboseTB.__init__(self, color_scheme=color_scheme, call_pdb=call_pdb, @@ -1262,7 +1262,8 @@ class FormattedTB(VerboseTB, ListTB): # Different types of tracebacks are joined with different separators to # form a single string. They are taken from this dict - self._join_chars = dict(Plain='', Context='\n', Verbose='\n') + self._join_chars = dict(Plain='', Context='\n', Verbose='\n', + Minimal='') # set_mode also sets the tb_join_char attribute self.set_mode(mode) @@ -1280,6 +1281,8 @@ class FormattedTB(VerboseTB, ListTB): return VerboseTB.structured_traceback( self, etype, value, tb, tb_offset, number_of_lines_of_context ) + elif mode == 'Minimal': + return ListTB.get_exception_only(self, etype, value) else: # We must check the source cache because otherwise we can print # out-of-date source code. @@ -1324,6 +1327,9 @@ class FormattedTB(VerboseTB, ListTB): def verbose(self): self.set_mode(self.valid_modes[2]) + def minimal(self): + self.set_mode(self.valid_modes[3]) + #---------------------------------------------------------------------------- class AutoFormattedTB(FormattedTB):