diff --git a/jedi/parser/fast.py b/jedi/parser/fast.py index 65cc8502..0bf44baf 100644 --- a/jedi/parser/fast.py +++ b/jedi/parser/fast.py @@ -330,6 +330,13 @@ class FastParser(use_metaclass(CachedFastParser)): self.number_of_splits += 1 return text + def just_newlines(current_lines): + for line in current_lines: + line = line.lstrip('\t ') + if line and line[0] not in ('#', '\r'): + return False + return True + # Split only new lines. Distinction between \r\n is the tokenizer's # job. self._lines = source.split('\n') @@ -365,7 +372,7 @@ class FastParser(use_metaclass(CachedFastParser)): if m: in_flow = m.group(1) in FLOWS if not is_decorator and not in_flow: - if current_lines: + if not just_newlines(current_lines): yield gen_part() is_decorator = '@' == m.group(1) if not is_decorator: diff --git a/test/test_parser/test_fast_parser.py b/test/test_parser/test_fast_parser.py index 45e1384f..3aba7a97 100644 --- a/test/test_parser/test_fast_parser.py +++ b/test/test_parser/test_fast_parser.py @@ -181,7 +181,8 @@ def test_nested_funcs(): def test_func_with_for_and_comment(): - # The first newline is important, leave it. + # The first newline is important, leave it. It should not trigger another + # parser split. src = dedent("""\ def func(): @@ -190,7 +191,7 @@ def test_func_with_for_and_comment(): for a in [1]: # COMMENT a""") - check_fp(src, 2, 3) + check_fp(src, 2) check_fp('a\n' + src, 1, 3)