Show More
@@ -2150,12 +2150,9 b' class InteractiveShell(Configurable, Magic):' | |||||
2150 | self.showsyntaxerror() |
|
2150 | self.showsyntaxerror() | |
2151 | self.execution_count += 1 |
|
2151 | self.execution_count += 1 | |
2152 | return None |
|
2152 | return None | |
2153 |
|
||||
2154 | interactivity = 'last' # Last node to be run interactive |
|
|||
2155 | if len(cell.splitlines()) == 1: |
|
|||
2156 | interactivity = 'all' # Single line; run fully interactive |
|
|||
2157 |
|
2153 | |||
2158 |
self.run_ast_nodes(code_ast.body, cell_name, |
|
2154 | self.run_ast_nodes(code_ast.body, cell_name, | |
|
2155 | interactivity="last_expr") | |||
2159 |
|
2156 | |||
2160 | # Execute any registered post-execution functions. |
|
2157 | # Execute any registered post-execution functions. | |
2161 | for func, status in self._post_execute.iteritems(): |
|
2158 | for func, status in self._post_execute.iteritems(): | |
@@ -2175,7 +2172,7 b' class InteractiveShell(Configurable, Magic):' | |||||
2175 | # Each cell is a *single* input, regardless of how many lines it has |
|
2172 | # Each cell is a *single* input, regardless of how many lines it has | |
2176 | self.execution_count += 1 |
|
2173 | self.execution_count += 1 | |
2177 |
|
2174 | |||
2178 | def run_ast_nodes(self, nodelist, cell_name, interactivity='last'): |
|
2175 | def run_ast_nodes(self, nodelist, cell_name, interactivity='last_expr'): | |
2179 | """Run a sequence of AST nodes. The execution mode depends on the |
|
2176 | """Run a sequence of AST nodes. The execution mode depends on the | |
2180 | interactivity parameter. |
|
2177 | interactivity parameter. | |
2181 |
|
2178 | |||
@@ -2187,13 +2184,21 b' class InteractiveShell(Configurable, Magic):' | |||||
2187 | Will be passed to the compiler as the filename of the cell. Typically |
|
2184 | Will be passed to the compiler as the filename of the cell. Typically | |
2188 | the value returned by ip.compile.cache(cell). |
|
2185 | the value returned by ip.compile.cache(cell). | |
2189 | interactivity : str |
|
2186 | interactivity : str | |
2190 |
'all', 'last' or 'none', specifying which nodes should be |
|
2187 | 'all', 'last', 'last_expr' or 'none', specifying which nodes should be | |
2191 |
interactively (displaying output from expressions). |
|
2188 | run interactively (displaying output from expressions). 'last_expr' | |
2192 | this parameter will raise a ValueError. |
|
2189 | will run the last node interactively only if it is an expression (i.e. | |
|
2190 | expressions in loops or other blocks are not displayed. Other values | |||
|
2191 | for this parameter will raise a ValueError. | |||
2193 | """ |
|
2192 | """ | |
2194 | if not nodelist: |
|
2193 | if not nodelist: | |
2195 | return |
|
2194 | return | |
2196 |
|
2195 | |||
|
2196 | if interactivity == 'last_expr': | |||
|
2197 | if isinstance(nodelist[-1], ast.Expr): | |||
|
2198 | interactivity = "last" | |||
|
2199 | else: | |||
|
2200 | interactivity = "none" | |||
|
2201 | ||||
2197 | if interactivity == 'none': |
|
2202 | if interactivity == 'none': | |
2198 | to_run_exec, to_run_interactive = nodelist, [] |
|
2203 | to_run_exec, to_run_interactive = nodelist, [] | |
2199 | elif interactivity == 'last': |
|
2204 | elif interactivity == 'last': |
General Comments 0
You need to be logged in to leave comments.
Login now