Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions IPython/core/inputsplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,18 +444,22 @@ def push_accepts_more(self):
return True

# If we already have complete input and we're flush left, the answer
# depends. In line mode, we're done. But in cell mode, we need to
# check how many blocks the input so far compiles into, because if
# there's already more than one full independent block of input, then
# the client has entered full 'cell' mode and is feeding lines that
# each is complete. In this case we should then keep accepting.
# The Qt terminal-like console does precisely this, to provide the
# convenience of terminal-like input of single expressions, but
# allowing the user (with a separate keystroke) to switch to 'cell'
# mode and type multiple expressions in one shot.
# depends. In line mode, if there hasn't been any indentation,
# that's it. If we've come back from some indentation, we need
# the blank final line to finish.
# In cell mode, we need to check how many blocks the input so far
# compiles into, because if there's already more than one full
# independent block of input, then the client has entered full
# 'cell' mode and is feeding lines that each is complete. In this
# case we should then keep accepting. The Qt terminal-like console
# does precisely this, to provide the convenience of terminal-like
# input of single expressions, but allowing the user (with a
# separate keystroke) to switch to 'cell' mode and type multiple
# expressions in one shot.
if self.indent_spaces==0:
if self.input_mode=='line':
return False
if not self._full_dedent:
return False
else:
nblocks = len(split_blocks(''.join(self._buffer)))
if nblocks==1:
Expand Down
11 changes: 11 additions & 0 deletions IPython/core/tests/test_inputsplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,17 @@ def test_push_accepts_more4(self):
self.assertTrue(isp.push_accepts_more())
isp.push('')
self.assertFalse(isp.push_accepts_more())

def test_push_accepts_more5(self):
# In cell mode, inputs must be fed in whole blocks, so skip this test
if self.isp.input_mode == 'cell': return

isp = self.isp
isp.push('try:')
isp.push(' a = 5')
isp.push('except:')
isp.push(' raise')
self.assertTrue(isp.push_accepts_more())

def test_continuation(self):
isp = self.isp
Expand Down