##// END OF EJS Templates
Fix indentation for nested block
Nguyen Duy Hai -
Show More
@@ -655,7 +655,15 b' class TransformerManager:'
655 if len(tokens_by_line) == 1 and not tokens_by_line[-1]:
655 if len(tokens_by_line) == 1 and not tokens_by_line[-1]:
656 return 'incomplete', 0
656 return 'incomplete', 0
657
657
658 if tokens_by_line[-1][-1].string == ':':
658 new_block = False
659 for token in reversed(tokens_by_line[-1]):
660 if token.type == tokenize.DEDENT:
661 continue
662 elif token.string == ':':
663 new_block = True
664 break
665
666 if new_block:
659 # The last line starts a block (e.g. 'if foo:')
667 # The last line starts a block (e.g. 'if foo:')
660 ix = 0
668 ix = 0
661 while tokens_by_line[-1][ix].type in {tokenize.INDENT, tokenize.DEDENT}:
669 while tokens_by_line[-1][ix].type in {tokenize.INDENT, tokenize.DEDENT}:
@@ -207,6 +207,7 b' def test_check_complete():'
207 cc = ipt2.TransformerManager().check_complete
207 cc = ipt2.TransformerManager().check_complete
208 nt.assert_equal(cc("a = 1"), ('complete', None))
208 nt.assert_equal(cc("a = 1"), ('complete', None))
209 nt.assert_equal(cc("for a in range(5):"), ('incomplete', 4))
209 nt.assert_equal(cc("for a in range(5):"), ('incomplete', 4))
210 nt.assert_equal(cc("for a in range(5):\n if a > 0:"), ('incomplete', 8))
210 nt.assert_equal(cc("raise = 2"), ('invalid', None))
211 nt.assert_equal(cc("raise = 2"), ('invalid', None))
211 nt.assert_equal(cc("a = [1,\n2,"), ('incomplete', 0))
212 nt.assert_equal(cc("a = [1,\n2,"), ('incomplete', 0))
212 nt.assert_equal(cc(")"), ('incomplete', 0))
213 nt.assert_equal(cc(")"), ('incomplete', 0))
General Comments 0
You need to be logged in to leave comments. Login now