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