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
- Fix #11334: Cannot make multi-line code blocks in ipython When codeop.compile_command() returns None it actually says "at least some part of the code was compiled successfully" which is not really im... — committed to bxsx/ipython by bxsx 6 years ago
- annother attmpt at https://github.com/ipython/ipython/issues/11334 — committed to Carreau/ipython by Carreau 6 years ago
The PR #11354 is updated now.
Upper case I please, we don’t want trouble with apple.
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
it runs
check_complete
on each line ending, which, in turn, executescompile_command
, and the latter one raises aSyntaxError
because ‘async with’ is used outside of the async function. In my fork I just muted thatSyntaxError
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 specificSyntaxError
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 raiseSyntaxError
, 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 aroundI’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.
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).