From 002a480a1df4fa7df5a69c469745f344fca92bd5 2011-07-11 20:36:32 From: Min RK Date: 2011-07-11 20:36:32 Subject: [PATCH] Merge pull request #567 from ivanov/inputsplit-trailing-whitespace ignore trailing whitespace after colon for autoindent --- diff --git a/IPython/core/inputsplitter.py b/IPython/core/inputsplitter.py index 9612d5b..978f115 100644 --- a/IPython/core/inputsplitter.py +++ b/IPython/core/inputsplitter.py @@ -434,7 +434,7 @@ class InputSplitter(object): #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 diff --git a/IPython/core/tests/test_inputsplitter.py b/IPython/core/tests/test_inputsplitter.py index 1b8422a..9b38ef8 100644 --- a/IPython/core/tests/test_inputsplitter.py +++ b/IPython/core/tests/test_inputsplitter.py @@ -200,6 +200,21 @@ class InputSplitterTestCase(unittest.TestCase): 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