Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

`yield`, `break`, and `continue` automatically dedent

Previously `return`, `raise`, and `pass` did; now these do as well.  The tests
for these were copied from the tests for those.
  • Loading branch information...
commit df408e2d93434fea17f718a7af15d3477911d2f8 1 parent 9bd0c90
@asmeurer asmeurer authored
View
6 IPython/core/inputsplitter.py
@@ -115,7 +115,11 @@
r'^\s+raise\([^\)]*\).*$', # wacky raise with immediate open paren
r'^\s+return(\s.*)?$', # normal return (+ space + other stuff, maybe)
r'^\s+return\([^\)]*\).*$', # wacky return with immediate open paren
- r'^\s+pass\s*$' # pass (optionally followed by trailing spaces)
+ r'^\s+yield(\s.*)?$', # normal yield (+ space + other stuff, maybe)
+ r'^\s+yield\([^\)]*\).*$', # wacky yield with immediate open paren
+ r'^\s+pass\s*$', # pass (optionally followed by trailing spaces)
+ r'^\s+break\s*$', # break (optionally followed by trailing spaces)
+ r'^\s+continue\s*$', # continue (optionally followed by trailing spaces)
]))
ini_spaces_re = re.compile(r'^([ \t\r\f\v]+)')
View
34 IPython/core/tests/test_inputsplitter.py
@@ -227,6 +227,26 @@ def test_dedent_pass(self):
isp.push('if 1:\n pass ')
self.assertEqual(isp.indent_spaces, 0)
+ def test_dedent_break(self):
+ isp = self.isp # shorthand
+ # should NOT cause dedent
+ isp.push('while 1:\n breaks = 5')
+ self.assertEqual(isp.indent_spaces, 4)
+ isp.push('while 1:\n break')
+ self.assertEqual(isp.indent_spaces, 0)
+ isp.push('while 1:\n break ')
+ self.assertEqual(isp.indent_spaces, 0)
+
+ def test_dedent_continue(self):
+ isp = self.isp # shorthand
+ # should NOT cause dedent
+ isp.push('while 1:\n continues = 5')
+ self.assertEqual(isp.indent_spaces, 4)
+ isp.push('while 1:\n continue')
+ self.assertEqual(isp.indent_spaces, 0)
+ isp.push('while 1:\n continue ')
+ self.assertEqual(isp.indent_spaces, 0)
+
def test_dedent_raise(self):
isp = self.isp # shorthand
# should NOT cause dedent
@@ -253,6 +273,20 @@ def test_dedent_return(self):
isp.push('if 1:\n return(0)')
self.assertEqual(isp.indent_spaces, 0)
+ def test_dedent_yield(self):
+ isp = self.isp # shorthand
+ # should NOT cause dedent
+ isp.push('if 1:\n yielding = 4')
+ self.assertEqual(isp.indent_spaces, 4)
+ isp.push('if 1:\n yield 5 + 493')
+ self.assertEqual(isp.indent_spaces, 0)
+ isp.push('if 1:\n yield')
+ self.assertEqual(isp.indent_spaces, 0)
+ isp.push('if 1:\n yield ')
+ self.assertEqual(isp.indent_spaces, 0)
+ isp.push('if 1:\n yield(0)')
+ self.assertEqual(isp.indent_spaces, 0)
+
def test_push(self):
isp = self.isp
self.assertTrue(isp.push('x=1'))
Please sign in to comment.
Something went wrong with that request. Please try again.