From 2fcb1b9b6583bbf8e0fe234123c6d9df813aa799 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 23 Feb 2015 01:00:17 +0100 Subject: [PATCH] Fast parser fix. --- jedi/parser/fast.py | 9 ++++----- test/test_parser/test_fast_parser.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) 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'