Skip to content

Commit 9fd29c9

Browse files
committed
Fixes to restore Python 2 support
1 parent a780c06 commit 9fd29c9

3 files changed

Lines changed: 22 additions & 19 deletions

File tree

IPython/core/magics/execution.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,25 @@ def _repr_pretty_(self, p , cycle):
8686
p.text(u'<TimeitResult : '+unic+u'>')
8787

8888

89+
class TimeitTemplateFiller(ast.NodeTransformer):
90+
"This is quite tightly tied to the template definition above."
91+
def __init__(self, ast_setup, ast_stmt):
92+
self.ast_setup = ast_setup
93+
self.ast_stmt = ast_stmt
94+
95+
def visit_FunctionDef(self, node):
96+
"Fill in the setup statement"
97+
self.generic_visit(node)
98+
if node.name == "inner":
99+
node.body[:1] = self.ast_setup.body
100+
101+
return node
102+
103+
def visit_For(self, node):
104+
"Fill in the statement to be timed"
105+
if getattr(getattr(node.body[0], 'value', None), 'id', None) == 'stmt':
106+
node.body = self.ast_stmt.body
107+
return node
89108

90109

91110
@magics_class
@@ -949,23 +968,7 @@ def timeit(self, line='', cell=None):
949968
' _t1 = _timer()\n'
950969
' return _t1 - _t0\n')
951970

952-
class TimeitTemplateFiller(ast.NodeTransformer):
953-
"This is quite tightly tied to the template definition above."
954-
def visit_FunctionDef(self, node):
955-
"Fill in the setup statement"
956-
self.generic_visit(node)
957-
if node.name == "inner":
958-
node.body[:1] = ast_setup.body
959-
960-
return node
961-
962-
def visit_For(self, node):
963-
"Fill in the statement to be timed"
964-
if getattr(getattr(node.body[0], 'value', None), 'id', None) == 'stmt':
965-
node.body = ast_stmt.body
966-
return node
967-
968-
timeit_ast = TimeitTemplateFiller().visit(timeit_ast_template)
971+
timeit_ast = TimeitTemplateFiller(ast_setup, ast_stmt).visit(timeit_ast_template)
969972
timeit_ast = ast.fix_missing_locations(timeit_ast)
970973

971974
# Track compilation time so it can be reported if too long

IPython/utils/PyColorize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
formatting (which is the hard part).
3030
"""
3131
from __future__ import print_function
32-
32+
from __future__ import absolute_import
3333
from __future__ import unicode_literals
3434

3535
__all__ = ['ANSICodeColors','Parser']

IPython/utils/capture.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Distributed under the terms of the BSD License. The full license is in
1010
# the file COPYING, distributed as part of this software.
1111
#-----------------------------------------------------------------------------
12-
from __future__ import print_function
12+
from __future__ import print_function, absolute_import
1313

1414
#-----------------------------------------------------------------------------
1515
# Imports

0 commit comments

Comments
 (0)