Permalink
Browse files

Merge pull request #567 from ivanov/inputsplit-trailing-whitespace

ignore trailing whitespace after colon for autoindent
  • Loading branch information...
2 parents d306e58 + e69ecd4 commit 002a480a1df4fa7df5a69c469745f344fca92bd5 @minrk minrk committed Jul 11, 2011
Showing with 16 additions and 1 deletion.
  1. +1 −1 IPython/core/inputsplitter.py
  2. +15 −0 IPython/core/tests/test_inputsplitter.py
@@ -434,7 +434,7 @@ def _find_indent(self, line):
#print 'Full dedent in text',self.source # dbg
full_dedent = True
- if line[-1] == ':':
+ if line.rstrip()[-1] == ':':
indent_spaces += 4
elif dedent_re.match(line):
indent_spaces -= 4
@@ -200,6 +200,21 @@ def test_indent3(self):
isp.push("if 1:")
isp.push(" x = (1+\n 2)")
self.assertEqual(isp.indent_spaces, 4)
+
+ def test_indent4(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
+ # whitespace after ':' should not screw up indent level
+ isp.push('if 1: \n x=1')
+ self.assertEqual(isp.indent_spaces, 4)
+ isp.push('y=2\n')
+ self.assertEqual(isp.indent_spaces, 0)
+ isp.push('if 1:\t\n x=1')
+ self.assertEqual(isp.indent_spaces, 4)
+ isp.push('y=2\n')
+ self.assertEqual(isp.indent_spaces, 0)
def test_dedent_pass(self):
isp = self.isp # shorthand

0 comments on commit 002a480

Please sign in to comment.