diff --git a/jedi/parser/fast.py b/jedi/parser/fast.py index a313229f..74c60200 100644 --- a/jedi/parser/fast.py +++ b/jedi/parser/fast.py @@ -478,15 +478,15 @@ class FastTokenizer(object): if typ == INDENT: self._indent_counter += 1 - if not self._expect_indent and not self._first_stmt: - # This does not mean that there is an actual flow, but it means - # that the INDENT is either syntactically wrong or a flow. + if not self._expect_indent and not self._first_stmt and not self._in_flow: + # This does not mean that there is an actual flow, it means + # that the INDENT is syntactically wrong. + self._flow_indent_counter = self._indent_counter - 1 self._in_flow = True self._expect_indent = False elif typ == DEDENT: self._indent_counter -= 1 if self._in_flow: - # TODO add <= for flows without INDENT in classes. if self._indent_counter == self._flow_indent_counter: self._in_flow = False else: @@ -507,7 +507,6 @@ class FastTokenizer(object): # new lines. if self.previous[0] in (NEWLINE, INDENT, DEDENT) \ and not self._parentheses_level and typ not in (INDENT, DEDENT): - # Check for NEWLINE, which symbolizes the indent. if not self._in_flow: if value in FLOWS: self._flow_indent_counter = self._indent_counter diff --git a/test/test_parser/test_fast_parser.py b/test/test_parser/test_fast_parser.py index 0324603b..47342d1e 100644 --- a/test/test_parser/test_fast_parser.py +++ b/test/test_parser/test_fast_parser.py @@ -322,6 +322,18 @@ def test_wrong_indentation(): """) check_fp(src, 1) + src = dedent("""\ + def complex(): + def nested(): + a + b + a + + def other(): + pass + """) + check_fp(src, 3) + def test_open_parentheses(): func = 'def func():\n a'