Multiline input push #372

merged 2 commits into from Apr 12, 2011


None yet

2 participants


To see this bug, start a Qt console and enter something like this (just using the return key, not ctrl-return):

if True:
    a = 1
b = [1,

(at this point, you get a SyntaxError).

The trouble is codeop.CommandCompiler, the tool we use in inputsplitter to distinguish a syntax error from an incomplete cell. By default, it compiles in "single" mode, which doesn't work properly with multiple statements. This patch uses "exec" mode instead.

The documentation for codeop says that only "single" and "eval" are valid arguments, but a look at the code reveals that the argument is ultimately just passed to compile, and using "exec" works with everything I've tried throwing at it. I guess it was invalid in older versions, and the documentation hasn't been updated (the docs for codeop describe backwards compatibility with Python 2.1).

There is also a test (which fails without the patch).

fperez commented Apr 12, 2011

Looks good to me, go for it. Thanks!

@takluyver takluyver merged commit e55836e into ipython:master Apr 12, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment