diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 0c6d8b4..3f31823 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -578,7 +578,7 @@ class InteractiveShell(SingletonConfigurable): @observe('colors') def init_syntax_highlighting(self, changes=None): # Python source parser/formatter for syntax highlighting - pyformat = PyColorize.Parser(style=self.colors).format + pyformat = PyColorize.Parser(style=self.colors, parent=self).format self.pycolorize = lambda src: pyformat(src,'str') def refresh_style(self): @@ -1569,7 +1569,7 @@ class InteractiveShell(SingletonConfigurable): def init_traceback_handlers(self, custom_exceptions): # Syntax error handler. - self.SyntaxTB = ultratb.SyntaxTB(color_scheme='NoColor') + self.SyntaxTB = ultratb.SyntaxTB(color_scheme='NoColor', parent=self) # The interactive one is initialized with an offset, meaning we always # want to remove the topmost item in the traceback, which is our own @@ -1578,7 +1578,7 @@ class InteractiveShell(SingletonConfigurable): color_scheme='NoColor', tb_offset = 1, check_cache=check_linecache_ipython, - debugger_cls=self.debugger_cls) + debugger_cls=self.debugger_cls, parent=self) # The instance will store a pointer to the system-wide exception hook, # so that runtime code (such as magics) can access it. This is because diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py index 52560b7..e03fda4 100644 --- a/IPython/core/ultratb.py +++ b/IPython/core/ultratb.py @@ -387,13 +387,11 @@ def _fixed_getinnerframes(etb, context=1, tb_offset=0): # (SyntaxErrors have to be treated specially because they have no traceback) -def _format_traceback_lines(lnum, index, lines, Colors, lvals=None, scheme=None): +def _format_traceback_lines(lnum, index, lines, Colors, lvals=None, _line_format=(lambda x,_:x,None)): numbers_width = INDENT_SIZE - 1 res = [] i = lnum - index - _line_format = PyColorize.Parser(style=scheme).format2 - for line in lines: line = py3compat.cast_unicode(line) @@ -586,9 +584,9 @@ class ListTB(TBTools): Because they are meant to be called without a full traceback (only a list), instances of this class can't call the interactive pdb debugger.""" - def __init__(self, color_scheme='NoColor', call_pdb=False, ostream=None, parent=None): + def __init__(self, color_scheme='NoColor', call_pdb=False, ostream=None, parent=None, config=None): TBTools.__init__(self, color_scheme=color_scheme, call_pdb=call_pdb, - ostream=ostream, parent=parent) + ostream=ostream, parent=parent,config=config) def __call__(self, etype, value, elist): self.ostream.flush() @@ -801,7 +799,8 @@ class VerboseTB(TBTools): def __init__(self, color_scheme='Linux', call_pdb=False, ostream=None, tb_offset=0, long_header=False, include_vars=True, - check_cache=None, debugger_cls = None): + check_cache=None, debugger_cls = None, + parent=None, config=None): """Specify traceback offset, headers and color scheme. Define how many frames to drop from the tracebacks. Calling it with @@ -809,7 +808,7 @@ class VerboseTB(TBTools): their own code at the top of the traceback (VerboseTB will first remove that frame before printing the traceback info).""" TBTools.__init__(self, color_scheme=color_scheme, call_pdb=call_pdb, - ostream=ostream) + ostream=ostream, parent=parent, config=config) self.tb_offset = tb_offset self.long_header = long_header self.include_vars = include_vars @@ -1010,9 +1009,10 @@ class VerboseTB(TBTools): if index is None: return level else: + _line_format = PyColorize.Parser(style=col_scheme, parent=self).format2 return '%s%s' % (level, ''.join( _format_traceback_lines(lnum, index, lines, Colors, lvals, - col_scheme))) + _line_format))) def prepare_chained_exception_message(self, cause): direct_cause = "\nThe above exception was the direct cause of the following exception:\n" @@ -1277,7 +1277,8 @@ class FormattedTB(VerboseTB, ListTB): def __init__(self, mode='Plain', color_scheme='Linux', call_pdb=False, ostream=None, tb_offset=0, long_header=False, include_vars=False, - check_cache=None, debugger_cls=None): + check_cache=None, debugger_cls=None, + parent=None, config=None): # NEVER change the order of this list. Put new modes at the end: self.valid_modes = ['Plain', 'Context', 'Verbose'] @@ -1286,7 +1287,8 @@ class FormattedTB(VerboseTB, ListTB): VerboseTB.__init__(self, color_scheme=color_scheme, call_pdb=call_pdb, ostream=ostream, tb_offset=tb_offset, long_header=long_header, include_vars=include_vars, - check_cache=check_cache, debugger_cls=debugger_cls) + check_cache=check_cache, debugger_cls=debugger_cls, + parent=parent, config=config) # Different types of tracebacks are joined with different separators to # form a single string. They are taken from this dict @@ -1415,8 +1417,8 @@ class ColorTB(FormattedTB): class SyntaxTB(ListTB): """Extension which holds some state: the last exception value""" - def __init__(self, color_scheme='NoColor'): - ListTB.__init__(self, color_scheme) + def __init__(self, color_scheme='NoColor', parent=None, config=None): + ListTB.__init__(self, color_scheme, parent=parent, config=config) self.last_syntax_error = None def __call__(self, etype, value, elist): diff --git a/IPython/utils/PyColorize.py b/IPython/utils/PyColorize.py index c845dd7..15e77e3 100644 --- a/IPython/utils/PyColorize.py +++ b/IPython/utils/PyColorize.py @@ -44,12 +44,7 @@ import sys import token import tokenize -try: - generate_tokens = tokenize.generate_tokens -except AttributeError: - # Python 3. Note that we use the undocumented _tokenize because it expects - # strings, not bytes. See also Python issue #9969. - generate_tokens = tokenize._tokenize +generate_tokens = tokenize.generate_tokens from IPython.utils.coloransi import TermColors, InputTermColors ,ColorScheme, ColorSchemeTable from IPython.utils.py3compat import PY3