From 9fd29c9c34d4761d2a468243d4db2dd177069dac 2013-10-29 16:15:55 From: Thomas Kluyver Date: 2013-10-29 16:15:55 Subject: [PATCH] Fixes to restore Python 2 support --- diff --git a/IPython/core/magics/execution.py b/IPython/core/magics/execution.py index 219f4ee..6c2d86e 100644 --- a/IPython/core/magics/execution.py +++ b/IPython/core/magics/execution.py @@ -86,6 +86,25 @@ class TimeitResult(object): p.text(u'') +class TimeitTemplateFiller(ast.NodeTransformer): + "This is quite tightly tied to the template definition above." + def __init__(self, ast_setup, ast_stmt): + self.ast_setup = ast_setup + self.ast_stmt = ast_stmt + + def visit_FunctionDef(self, node): + "Fill in the setup statement" + self.generic_visit(node) + if node.name == "inner": + node.body[:1] = self.ast_setup.body + + return node + + def visit_For(self, node): + "Fill in the statement to be timed" + if getattr(getattr(node.body[0], 'value', None), 'id', None) == 'stmt': + node.body = self.ast_stmt.body + return node @magics_class @@ -949,23 +968,7 @@ python-profiler package from non-free.""") ' _t1 = _timer()\n' ' return _t1 - _t0\n') - class TimeitTemplateFiller(ast.NodeTransformer): - "This is quite tightly tied to the template definition above." - def visit_FunctionDef(self, node): - "Fill in the setup statement" - self.generic_visit(node) - if node.name == "inner": - node.body[:1] = ast_setup.body - - return node - - def visit_For(self, node): - "Fill in the statement to be timed" - if getattr(getattr(node.body[0], 'value', None), 'id', None) == 'stmt': - node.body = ast_stmt.body - return node - - timeit_ast = TimeitTemplateFiller().visit(timeit_ast_template) + timeit_ast = TimeitTemplateFiller(ast_setup, ast_stmt).visit(timeit_ast_template) timeit_ast = ast.fix_missing_locations(timeit_ast) # Track compilation time so it can be reported if too long diff --git a/IPython/utils/PyColorize.py b/IPython/utils/PyColorize.py index 074b95d..aaafcfa 100644 --- a/IPython/utils/PyColorize.py +++ b/IPython/utils/PyColorize.py @@ -29,7 +29,7 @@ scan Python source code and re-emit it with no changes to its original formatting (which is the hard part). """ from __future__ import print_function - +from __future__ import absolute_import from __future__ import unicode_literals __all__ = ['ANSICodeColors','Parser'] diff --git a/IPython/utils/capture.py b/IPython/utils/capture.py index e7b96ac..a871d96 100644 --- a/IPython/utils/capture.py +++ b/IPython/utils/capture.py @@ -9,7 +9,7 @@ IO capturing utilities. # Distributed under the terms of the BSD License. The full license is in # the file COPYING, distributed as part of this software. #----------------------------------------------------------------------------- -from __future__ import print_function +from __future__ import print_function, absolute_import #----------------------------------------------------------------------------- # Imports