##// END OF EJS Templates
Fixes to restore Python 2 support
Thomas Kluyver -
Show More
@@ -86,6 +86,25 b' class TimeitResult(object):'
86 p.text(u'<TimeitResult : '+unic+u'>')
86 p.text(u'<TimeitResult : '+unic+u'>')
87
87
88
88
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
89
108
90
109
91 @magics_class
110 @magics_class
@@ -949,23 +968,7 b' python-profiler package from non-free.""")'
949 ' _t1 = _timer()\n'
968 ' _t1 = _timer()\n'
950 ' return _t1 - _t0\n')
969 ' return _t1 - _t0\n')
951
970
952 class TimeitTemplateFiller(ast.NodeTransformer):
971 timeit_ast = TimeitTemplateFiller(ast_setup, ast_stmt).visit(timeit_ast_template)
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)
969 timeit_ast = ast.fix_missing_locations(timeit_ast)
972 timeit_ast = ast.fix_missing_locations(timeit_ast)
970
973
971 # Track compilation time so it can be reported if too long
974 # Track compilation time so it can be reported if too long
@@ -29,7 +29,7 b' scan Python source code and re-emit it with no changes to its original'
29 formatting (which is the hard part).
29 formatting (which is the hard part).
30 """
30 """
31 from __future__ import print_function
31 from __future__ import print_function
32
32 from __future__ import absolute_import
33 from __future__ import unicode_literals
33 from __future__ import unicode_literals
34
34
35 __all__ = ['ANSICodeColors','Parser']
35 __all__ = ['ANSICodeColors','Parser']
@@ -9,7 +9,7 b' IO capturing utilities.'
9 # Distributed under the terms of the BSD License. The full license is in
9 # Distributed under the terms of the BSD License. The full license is in
10 # the file COPYING, distributed as part of this software.
10 # the file COPYING, distributed as part of this software.
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12 from __future__ import print_function
12 from __future__ import print_function, absolute_import
13
13
14 #-----------------------------------------------------------------------------
14 #-----------------------------------------------------------------------------
15 # Imports
15 # Imports
General Comments 0
You need to be logged in to leave comments. Login now