Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Simplify - call ast.parse inline, rather than via a separate method.

  • Loading branch information...
commit 8f249fb7a8f3669d6095dcb6cf39543abb51d064 1 parent 99cb78e
@takluyver authored
Showing with 4 additions and 21 deletions.
  1. +2 −19 IPython/core/inputsplitter.py
  2. +2 −2 IPython/core/interactiveshell.py
View
21 IPython/core/inputsplitter.py
@@ -446,11 +446,11 @@ def push_accepts_more(self):
return False
else:
try:
- nodes = self.ast_nodes()
+ code_ast = ast.parse(u''.join(self._buffer))
except Exception:
return False
else:
- if len(nodes) == 1:
+ if len(code_ast.body) == 1:
return False
# When input is complete, then termination is marked by an extra blank
@@ -539,23 +539,6 @@ def split_blocks(self, lines):
# python syntax, feed it back a second time through the AST-based
# splitter, which is more accurate than ours.
return split_blocks(''.join(blocks))
-
- def ast_nodes(self, lines=None):
- """Turn the lines into a list of AST nodes.
-
- Parameters
- ----------
- lines : str
- A (possibly multiline) string of Python code. If None (default), it
- will use the InputSplitter's current code buffer.
-
- Returns
- -------
- A list of AST (abstract syntax tree) nodes representing the code.
- """
- if lines is None:
- lines = u"".join(self._buffer)
- return ast.parse(lines).body
#------------------------------------------------------------------------
# Private interface
View
4 IPython/core/interactiveshell.py
@@ -2125,7 +2125,7 @@ def run_cell_NODE(self, cell, store_history=True):
with self.display_trap:
try:
- nodes = self.input_splitter.ast_nodes(cell)
+ code_ast = ast.parse(cell)
except (OverflowError, SyntaxError, ValueError, TypeError, MemoryError):
# Case 1
self.showsyntaxerror(filename)
@@ -2135,7 +2135,7 @@ def run_cell_NODE(self, cell, store_history=True):
if len(cell.splitlines()) == 1:
interactivity = 2 # Single line; run fully interactive
- self.run_ast_nodes(nodes, interactivity)
+ self.run_ast_nodes(code_ast.body, interactivity)
if store_history:
# Write output to the database. Does nothing unless
Please sign in to comment.
Something went wrong with that request. Please try again.