ipython: Cannot make multi-line code blocks in ipython

I just did a pip install ipython while teaching a class today and typed an if statement and then hit enter after the first line and the code executed.

This seems like a bug.

I did a pip install ipython==6.5.0 and hitting Enter in a code block properly showed me the next indented line to type out.

I’m on Ubuntu 18.04 running ipython within tmux, though I doubt tmux is the issue here.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 12
  • Comments: 28 (16 by maintainers)

Commits related to this issue

Most upvoted comments

Actually, I got a regression with my fix. Fixing it now.

The PR #11354 is updated now.

iPython

Upper case I please, we don’t want trouble with apple.

You don’t need a few examples

Well, no I don’t need, but I want multiple example. I can reproduce and have an idea of how to fix it, but having multiple case help me be sure that I’m no hitting an edge case. I do have a biased view on how to use IPython, so example from other are helpful.

you can use ctrl-o to force a new line.

Is there a way to disable multiline commands? Most time it is useful but sometimes it leads to problems when executing code in some enviroments. e.g.: This issue in VS Code

We could try something like this as well.

Oh, I didn’t think it’d attach to this issue. Anyway, the reason it fails is that when we have

async with aiohttp.ClientSession() as session:
    pass|   # < cursor is there

it runs check_complete on each line ending, which, in turn, executes compile_command, and the latter one raises a SyntaxError because ‘async with’ is used outside of the async function. In my fork I just muted that SyntaxError but it’s certainly not the brightest way to fix that, lol.

Possible solutions/ideas:

  • should check if the autoawait is turned on. if it is, could ignore that specific SyntaxError case. I don’t think it’s a good solution, but maybe I’m also overcomplicating things.

  • if the autoawait’s on, feed the compile_command() with the code wrapped with the _asyncify(). i guess, this way it won’t raise SyntaxError, but i’m not sure if the newline issue will be resolved because _asyncify() itself adds some levels of indentation and it easily can go messy.

  • maybe _AsyncSyntaxErrorVisitor can help any? But I guess it’s for the other way around

I’m sorry for the lack of dedication, I’d submit thw PR, but I hate writing tests and whatnot and also not sure of the better way to fix that. But I hope it’s still useful for someone.

iPython Upper case I please, we don’t want trouble with apple.

At least I found out why there was the the upper I in the name, thanks and sorry 😃

As a apology, here is a pull request #11354 that fixes this (major) issue. IMHO this is a blocking bug for IPython, you should consider to make a release soon (see how many issues is created at github by users regarding it).