mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +08:00
Fix multi line param issues in the fast parser.
This commit is contained in:
@@ -275,7 +275,8 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
self._lines = source.splitlines(True)
|
self._lines = source.splitlines(True)
|
||||||
current_lines = []
|
current_lines = []
|
||||||
is_decorator = False
|
is_decorator = False
|
||||||
indent_list = [0]
|
# Use -1, because that indent is always smaller than any other.
|
||||||
|
indent_list = [-1, 0]
|
||||||
new_indent = False
|
new_indent = False
|
||||||
flow_indent = None
|
flow_indent = None
|
||||||
# All things within flows are simply being ignored.
|
# All things within flows are simply being ignored.
|
||||||
@@ -287,7 +288,13 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
current_lines.append(l) # just ignore comments and blank lines
|
current_lines.append(l) # just ignore comments and blank lines
|
||||||
continue
|
continue
|
||||||
|
|
||||||
while indent < indent_list[-1]: # -> dedent
|
if new_indent:
|
||||||
|
if indent > indent_list[-2]:
|
||||||
|
# Set the actual indent, not just the random old indent + 1.
|
||||||
|
indent_list[-1] = indent
|
||||||
|
new_indent = False
|
||||||
|
|
||||||
|
while indent <= indent_list[-2]: # -> dedent
|
||||||
indent_list.pop()
|
indent_list.pop()
|
||||||
# This automatically resets the flow_indent if there was a
|
# This automatically resets the flow_indent if there was a
|
||||||
# dedent or a flow just on one line (with one simple_stmt).
|
# dedent or a flow just on one line (with one simple_stmt).
|
||||||
@@ -297,12 +304,6 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
yield gen_part()
|
yield gen_part()
|
||||||
flow_indent = None
|
flow_indent = None
|
||||||
|
|
||||||
if new_indent:
|
|
||||||
if indent > indent_list[-1]:
|
|
||||||
# Set the actual indent, not just the random old indent + 1.
|
|
||||||
indent_list[-1] = indent
|
|
||||||
new_indent = False
|
|
||||||
|
|
||||||
# Check lines for functions/classes and split the code there.
|
# Check lines for functions/classes and split the code there.
|
||||||
if flow_indent is None:
|
if flow_indent is None:
|
||||||
m = self._keyword_re.match(l)
|
m = self._keyword_re.match(l)
|
||||||
@@ -358,7 +359,6 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
else:
|
else:
|
||||||
debug.dbg('While parsing %s, line %s slowed down the fast parser',
|
debug.dbg('While parsing %s, line %s slowed down the fast parser',
|
||||||
self.module_path, line_offset)
|
self.module_path, line_offset)
|
||||||
print(line_offset, repr(code_part))
|
|
||||||
|
|
||||||
line_offset += code_part.count('\n')
|
line_offset += code_part.count('\n')
|
||||||
start += len(code_part)
|
start += len(code_part)
|
||||||
|
|||||||
@@ -244,6 +244,17 @@ def test_func_with_for_and_comment():
|
|||||||
check_fp('a\n' + src, 2, 3)
|
check_fp('a\n' + src, 2, 3)
|
||||||
|
|
||||||
|
|
||||||
|
def test_multi_line_params():
|
||||||
|
src = dedent("""\
|
||||||
|
def x(a,
|
||||||
|
b):
|
||||||
|
pass
|
||||||
|
|
||||||
|
foo = 1
|
||||||
|
""")
|
||||||
|
check_fp(src, 2)
|
||||||
|
|
||||||
|
|
||||||
def test_one_statement_func():
|
def test_one_statement_func():
|
||||||
src = dedent("""\
|
src = dedent("""\
|
||||||
first
|
first
|
||||||
|
|||||||
Reference in New Issue
Block a user