Browse files

Fix bug where bare strings would be silently ignored in input.

Bare strings are parsed by the AST module as the docstring of the
'module' (in our case, the string of user input), so they need to be
  • Loading branch information...
rkern authored and fperez committed Jan 28, 2011
1 parent 21940ff commit 2ccc90d68ac01145ab97ba9cd2457e3911540ea4
Showing with 17 additions and 1 deletion.
  1. +8 −1 IPython/core/
  2. +9 −0 IPython/core/tests/
@@ -225,6 +225,13 @@ def split_blocks(python):
# to put in a more sophisticated test.
linenos = [x.lineno-1 for x in ast.node if x.lineno is not None]
# When we have a bare string as the first statement, it does not end up as
# a Discard Node in the AST as we might expect. Instead, it gets interpreted
# as the docstring of the module. Check for this case and prepend 0 (the
# first line number) to the list of linenos to account for it.
if ast.doc is not None:
linenos.insert(0, 0)
# When we finally get the slices, we will need to slice all the way to
# the end even though we don't have a line number for it. Fortunately,
# None does the job nicely.
@@ -347,7 +354,7 @@ def source_reset(self):
return out
def push(self, lines):
"""Push one ore more lines of input.
"""Push one or more lines of input.
This stores the given lines and returns a status code indicating
whether the code forms a complete Python block or not.
@@ -329,6 +329,15 @@ def test_split(self):
[['for i in range(10):'
' x=i**2'],
['z = 1']],
for block_lines in all_blocks:

0 comments on commit 2ccc90d

Please sign in to comment.