mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-19 20:11:12 +08:00
for loops are now parsed even if they are really faulty and don't end.
This commit is contained in:
@@ -567,10 +567,12 @@ class Parser(object):
|
|||||||
set_stmt, tok = self._parse_statement(added_breaks=['in'],
|
set_stmt, tok = self._parse_statement(added_breaks=['in'],
|
||||||
names_are_set_vars=True)
|
names_are_set_vars=True)
|
||||||
if tok != 'in':
|
if tok != 'in':
|
||||||
debug.warning('syntax err, for flow incomplete @%s',
|
debug.warning('syntax err, for flow incomplete @%s', self.start_pos[0])
|
||||||
self.start_pos[0])
|
|
||||||
|
|
||||||
statement, tok = self._parse_statement()
|
try:
|
||||||
|
statement, tok = self._parse_statement()
|
||||||
|
except StopIteration:
|
||||||
|
statement, tok = None, None
|
||||||
s = [] if statement is None else [statement]
|
s = [] if statement is None else [statement]
|
||||||
f = pr.ForFlow(self.module, s, first_pos, set_stmt)
|
f = pr.ForFlow(self.module, s, first_pos, set_stmt)
|
||||||
self._scope = self._scope.add_statement(f)
|
self._scope = self._scope.add_statement(f)
|
||||||
|
|||||||
@@ -275,6 +275,10 @@ class Scope(Simple, IsScope):
|
|||||||
if self.isinstance(Function):
|
if self.isinstance(Function):
|
||||||
checks += self.params + self.decorators
|
checks += self.params + self.decorators
|
||||||
checks += [r for r in self.returns if r is not None]
|
checks += [r for r in self.returns if r is not None]
|
||||||
|
if self.isinstance(Flow):
|
||||||
|
checks += self.inputs
|
||||||
|
if isinstance(self, ForFlow):
|
||||||
|
checks.append(self.set_stmt)
|
||||||
|
|
||||||
for s in checks:
|
for s in checks:
|
||||||
if isinstance(s, Flow):
|
if isinstance(s, Flow):
|
||||||
|
|||||||
@@ -15,9 +15,11 @@ class TestCallSignatures(TestCase):
|
|||||||
assert signatures[0].call_name == expected_name
|
assert signatures[0].call_name == expected_name
|
||||||
assert signatures[0].index == expected_index
|
assert signatures[0].index == expected_index
|
||||||
|
|
||||||
|
def _run_simple(self, source, name, index=0, column=None, line=1):
|
||||||
|
self._run(source, name, index, line, column)
|
||||||
|
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
def run(source, name, index=0, column=None, line=1):
|
run = self._run_simple
|
||||||
self._run(source, name, index, line, column)
|
|
||||||
|
|
||||||
# simple
|
# simple
|
||||||
s1 = "abs(a, str("
|
s1 = "abs(a, str("
|
||||||
@@ -60,18 +62,19 @@ class TestCallSignatures(TestCase):
|
|||||||
|
|
||||||
run("import time; abc = time; abc.sleep(", 'sleep', 0)
|
run("import time; abc = time; abc.sleep(", 'sleep', 0)
|
||||||
|
|
||||||
# jedi-vim #9
|
|
||||||
run("with open(", 'open', 0)
|
|
||||||
|
|
||||||
# jedi-vim #11
|
|
||||||
run("for sorted(", 'sorted', 0)
|
|
||||||
run("for s in sorted(", 'sorted', 0)
|
|
||||||
|
|
||||||
# jedi #57
|
# jedi #57
|
||||||
s = "def func(alpha, beta): pass\n" \
|
s = "def func(alpha, beta): pass\n" \
|
||||||
"func(alpha='101',"
|
"func(alpha='101',"
|
||||||
run(s, 'func', 0, column=13, line=2)
|
run(s, 'func', 0, column=13, line=2)
|
||||||
|
|
||||||
|
def test_flows(self):
|
||||||
|
# jedi-vim #9
|
||||||
|
self._run_simple("with open(", 'open', 0)
|
||||||
|
|
||||||
|
# jedi-vim #11
|
||||||
|
self._run_simple("for sorted(", 'sorted', 0)
|
||||||
|
self._run_simple("for s in sorted(", 'sorted', 0)
|
||||||
|
|
||||||
def test_complex(self):
|
def test_complex(self):
|
||||||
s = """
|
s = """
|
||||||
def abc(a,b):
|
def abc(a,b):
|
||||||
|
|||||||
Reference in New Issue
Block a user