Show More
@@ -604,7 +604,7 class TransformerManager: | |||||
604 | else: |
|
604 | else: | |
605 | continue |
|
605 | continue | |
606 |
|
606 | |||
607 | if ends_with_newline: |
|
607 | if not ends_with_newline: | |
608 | # Append an newline for consistent tokenization |
|
608 | # Append an newline for consistent tokenization | |
609 | # See https://bugs.python.org/issue33899 |
|
609 | # See https://bugs.python.org/issue33899 | |
610 | cell += '\n' |
|
610 | cell += '\n' | |
@@ -649,10 +649,13 class TransformerManager: | |||||
649 |
|
649 | |||
650 | newline_types = {tokenize.NEWLINE, tokenize.COMMENT, tokenize.ENDMARKER} |
|
650 | newline_types = {tokenize.NEWLINE, tokenize.COMMENT, tokenize.ENDMARKER} | |
651 |
|
651 | |||
652 | # Remove newline_types for the list of tokens |
|
652 | # Pop the last line which only contains DEDENTs and ENDMARKER | |
653 | while len(tokens_by_line) > 1 and len(tokens_by_line[-1]) == 1 \ |
|
653 | last_token_line = None | |
654 |
|
|
654 | if {t.type for t in tokens_by_line[-1]} in [ | |
655 | tokens_by_line.pop() |
|
655 | {tokenize.DEDENT, tokenize.ENDMARKER}, | |
|
656 | {tokenize.ENDMARKER} | |||
|
657 | ] and len(tokens_by_line) > 1: | |||
|
658 | last_token_line = tokens_by_line.pop() | |||
656 |
|
659 | |||
657 | while tokens_by_line[-1] and tokens_by_line[-1][-1].type in newline_types: |
|
660 | while tokens_by_line[-1] and tokens_by_line[-1][-1].type in newline_types: | |
658 | tokens_by_line[-1].pop() |
|
661 | tokens_by_line[-1].pop() | |
@@ -685,7 +688,7 class TransformerManager: | |||||
685 | if res is None: |
|
688 | if res is None: | |
686 | return 'incomplete', find_last_indent(lines) |
|
689 | return 'incomplete', find_last_indent(lines) | |
687 |
|
690 | |||
688 |
if |
|
691 | if last_token_line and last_token_line[0].type == tokenize.DEDENT: | |
689 | if ends_with_newline: |
|
692 | if ends_with_newline: | |
690 | return 'complete', None |
|
693 | return 'complete', None | |
691 | return 'incomplete', find_last_indent(lines) |
|
694 | return 'incomplete', find_last_indent(lines) |
@@ -238,6 +238,7 def test_check_complete(): | |||||
238 | cc = ipt2.TransformerManager().check_complete |
|
238 | cc = ipt2.TransformerManager().check_complete | |
239 | nt.assert_equal(cc("a = 1"), ('complete', None)) |
|
239 | nt.assert_equal(cc("a = 1"), ('complete', None)) | |
240 | nt.assert_equal(cc("for a in range(5):"), ('incomplete', 4)) |
|
240 | nt.assert_equal(cc("for a in range(5):"), ('incomplete', 4)) | |
|
241 | nt.assert_equal(cc("for a in range(5):\n if a > 0:"), ('incomplete', 8)) | |||
241 | nt.assert_equal(cc("raise = 2"), ('invalid', None)) |
|
242 | nt.assert_equal(cc("raise = 2"), ('invalid', None)) | |
242 | nt.assert_equal(cc("a = [1,\n2,"), ('incomplete', 0)) |
|
243 | nt.assert_equal(cc("a = [1,\n2,"), ('incomplete', 0)) | |
243 | nt.assert_equal(cc(")"), ('incomplete', 0)) |
|
244 | nt.assert_equal(cc(")"), ('incomplete', 0)) |
General Comments 0
You need to be logged in to leave comments.
Login now