Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiline input push #372

Merged
merged 2 commits into from Apr 12, 2011
Merged

Conversation

takluyver
Copy link
Member

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
Copy link
Member

fperez commented Apr 12, 2011

Looks good to me, go for it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants