mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-15 10:07:06 +08:00
Fix an issue with Function/Flow combination in the fast parser.
This commit is contained in:
@@ -542,6 +542,7 @@ class FastTokenizer(object):
|
|||||||
self._indent_counter += 1
|
self._indent_counter += 1
|
||||||
elif typ == DEDENT:
|
elif typ == DEDENT:
|
||||||
self._indent_counter -= 1
|
self._indent_counter -= 1
|
||||||
|
print('DEDENT', self._flow_indent_counter, start_pos, self._indent_counter)
|
||||||
if self._in_flow and self._indent_counter == self._flow_indent_counter:
|
if self._in_flow and self._indent_counter == self._flow_indent_counter:
|
||||||
self._in_flow = False
|
self._in_flow = False
|
||||||
self._next_dedent_noclose = True
|
self._next_dedent_noclose = True
|
||||||
@@ -549,10 +550,11 @@ class FastTokenizer(object):
|
|||||||
|
|
||||||
if self.previous[0] in (NEWLINE, INDENT, DEDENT):
|
if self.previous[0] in (NEWLINE, INDENT, DEDENT):
|
||||||
if self.previous[0] == DEDENT:
|
if self.previous[0] == DEDENT:
|
||||||
if not self._next_dedent_noclose:
|
|
||||||
self._first_stmt = False
|
|
||||||
return self._close()
|
|
||||||
if not self._in_flow:
|
if not self._in_flow:
|
||||||
|
if not self._next_dedent_noclose:
|
||||||
|
self._first_stmt = False
|
||||||
|
return self._close()
|
||||||
|
|
||||||
self._next_dedent_noclose = False
|
self._next_dedent_noclose = False
|
||||||
# Check for NEWLINE, which symbolizes the indent.
|
# Check for NEWLINE, which symbolizes the indent.
|
||||||
#print('X', repr(value), tokenize.tok_name[typ])
|
#print('X', repr(value), tokenize.tok_name[typ])
|
||||||
|
|||||||
@@ -142,6 +142,20 @@ def test_for():
|
|||||||
check_fp(src, 1)
|
check_fp(src, 1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_func_with_if():
|
||||||
|
src = dedent("""\
|
||||||
|
def recursion(a):
|
||||||
|
if foo:
|
||||||
|
return recursion(a)
|
||||||
|
else:
|
||||||
|
if bar:
|
||||||
|
return inexistent
|
||||||
|
else:
|
||||||
|
return a
|
||||||
|
""")
|
||||||
|
check_fp(src, 1)
|
||||||
|
|
||||||
|
|
||||||
def test_incomplete_function():
|
def test_incomplete_function():
|
||||||
source = '''return ImportErr'''
|
source = '''return ImportErr'''
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user