Ticket #12719: 12719-fix-transformer.patch

File 12719-fix-transformer.patch, 1.6 KB (added by jason, 9 years ago)
  • sage/misc/sage_extension.py

    # HG changeset patch
    # User Jason Grout <jason.grout@drake.edu>
    # Date 1348576794 18000
    # Branch ipython
    # Node ID 2f28f3e40ed55b7efc8e47a72944525cbf9ae65c
    # Parent  8476273e91c63e0e2262b3fd5e2624c60ffd297f
    Fix the input splitter so that transforms are run on lines following decorators.
    
    See http://mail.scipy.org/pipermail/ipython-dev/2012-September/010329.html
    
    diff --git a/sage/misc/sage_extension.py b/sage/misc/sage_extension.py
    a b  
    243243
    244244    # a direct copy of the IPython splitter, except that the
    245245    # transforms are called with the line numbers, and the transforms come from the class attribute
     246    # and except that we add a .startswith('@') in the test to see if we should transform a line
     247    # (see http://mail.scipy.org/pipermail/ipython-dev/2012-September/010329.html; the current behavior
     248    # doesn't run the preparser on a 'def' line following an decorator.
    246249    def push(self, lines):
    247250        """Push one or more lines of IPython input.
    248251
     
    322325            buf = self._buffer
    323326            for line in lines_list:
    324327                line_number = len(buf)
    325                 if self._is_complete or not buf or \
    326                        (buf and buf[-1].rstrip().endswith((':', ','))):
     328                if (self._is_complete or not buf or
     329                    buf[-1].rstrip().endswith((':', ',')) or buf[-1].lstrip().startswith('@')):
    327330                    for f in self.transforms:
    328331                        line = f(line, line_number)
    329332                out = push(line)