Fill in the AST template for timing execution. This is quite closely tied to the template definition, which is in :meth:`ExecutionMagics.timeit`.
| 135 | |
| 136 | |
| 137 | class TimeitTemplateFiller(ast.NodeTransformer): |
| 138 | """Fill in the AST template for timing execution. |
| 139 | |
| 140 | This is quite closely tied to the template definition, which is in |
| 141 | :meth:`ExecutionMagics.timeit`. |
| 142 | """ |
| 143 | def __init__(self, ast_setup, ast_stmt): |
| 144 | self.ast_setup = ast_setup |
| 145 | self.ast_stmt = ast_stmt |
| 146 | |
| 147 | def visit_FunctionDef(self, node): |
| 148 | "Fill in the setup statement" |
| 149 | self.generic_visit(node) |
| 150 | if node.name == "inner": |
| 151 | node.body[:1] = self.ast_setup.body |
| 152 | |
| 153 | return node |
| 154 | |
| 155 | def visit_For(self, node): |
| 156 | "Fill in the statement to be timed" |
| 157 | if getattr(getattr(node.body[0], 'value', None), 'id', None) == 'stmt': |
| 158 | node.body = self.ast_stmt.body |
| 159 | return node |
| 160 | |
| 161 | |
| 162 | class Timer(timeit.Timer): |
no outgoing calls
no test coverage detected
searching dependent graphs…