Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix trailing whitespace from reseting indentation

  • Loading branch information...
commit e69ecd40bd2832db569babe471fcba6aa7784a46 1 parent 26addb0
@ivanov authored
View
2  IPython/core/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
View
15 IPython/core/tests/test_inputsplitter.py
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.