forked from VimPlug/jedi
fix list comprehension problems for non-nested
This commit is contained in:
@@ -72,7 +72,6 @@ from _compatibility import next, hasattr, is_py3k, unicode
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import itertools
|
import itertools
|
||||||
import copy
|
|
||||||
|
|
||||||
import common
|
import common
|
||||||
import cache
|
import cache
|
||||||
@@ -566,10 +565,10 @@ def follow_call_list(call_list, follow_array=False):
|
|||||||
# is nested LC
|
# is nested LC
|
||||||
input = nested_lc.stmt
|
input = nested_lc.stmt
|
||||||
module = input.get_parent_until()
|
module = input.get_parent_until()
|
||||||
loop = pr.ForFlow(module, [input], lc.stmt.start_pos,
|
# create a for loop, which does the same as list comprehensions
|
||||||
lc.middle, True)
|
loop = pr.ForFlow(module, [input], lc.stmt.start_pos, lc.middle, True)
|
||||||
|
|
||||||
loop.parent = lc.stmt.parent if parent is None else parent
|
loop.parent = lc.parent if parent is None else parent
|
||||||
|
|
||||||
if isinstance(nested_lc, pr.ListComprehension):
|
if isinstance(nested_lc, pr.ListComprehension):
|
||||||
loop = evaluate_list_comprehension(nested_lc, loop)
|
loop = evaluate_list_comprehension(nested_lc, loop)
|
||||||
@@ -593,11 +592,10 @@ def follow_call_list(call_list, follow_array=False):
|
|||||||
position=call.start_pos)
|
position=call.start_pos)
|
||||||
elif isinstance(call, pr.ListComprehension):
|
elif isinstance(call, pr.ListComprehension):
|
||||||
loop = evaluate_list_comprehension(call)
|
loop = evaluate_list_comprehension(call)
|
||||||
stmt = copy.copy(call.stmt)
|
# Caveat: parents are being changed, but this doesn't matter,
|
||||||
stmt.parent = loop
|
# because nothing else uses it.
|
||||||
# create a for loop which does the same as list
|
call.stmt.parent = loop
|
||||||
# comprehensions
|
result += follow_statement(call.stmt)
|
||||||
result += follow_statement(stmt)
|
|
||||||
else:
|
else:
|
||||||
if isinstance(call, pr.Lambda):
|
if isinstance(call, pr.Lambda):
|
||||||
result.append(er.Function(call))
|
result.append(er.Function(call))
|
||||||
|
|||||||
@@ -435,8 +435,7 @@ class Parser(object):
|
|||||||
st = pr.Statement(self.module, src, [], [], [],
|
st = pr.Statement(self.module, src, [], [], [],
|
||||||
toks, first_pos, self.end_pos)
|
toks, first_pos, self.end_pos)
|
||||||
|
|
||||||
tok = pr.ListComprehension(st, middle, in_clause,
|
tok = pr.ListComprehension(st, middle, in_clause)
|
||||||
self.scope)
|
|
||||||
tok_list.append(tok)
|
tok_list.append(tok)
|
||||||
if list_comp:
|
if list_comp:
|
||||||
string = ''
|
string = ''
|
||||||
|
|||||||
@@ -93,8 +93,8 @@ class Simple(Base):
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
code = self.get_code().replace('\n', ' ')
|
code = self.get_code().replace('\n', ' ')
|
||||||
return "<%s: %s@%s>" % \
|
return "<%s: %s@%s,%s>" % \
|
||||||
(type(self).__name__, code, self.start_pos[0])
|
(type(self).__name__, code, self.start_pos[0], self.start_pos[0])
|
||||||
|
|
||||||
|
|
||||||
class IsScope(Base):
|
class IsScope(Base):
|
||||||
@@ -479,6 +479,7 @@ class Flow(Scope):
|
|||||||
self.set_vars = set_vars
|
self.set_vars = set_vars
|
||||||
for s in self.set_vars:
|
for s in self.set_vars:
|
||||||
s.parent.parent = self.use_as_parent
|
s.parent.parent = self.use_as_parent
|
||||||
|
# TODO strange!!! don't know why this exist
|
||||||
s.parent = self.use_as_parent
|
s.parent = self.use_as_parent
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -545,6 +546,7 @@ class ForFlow(Flow):
|
|||||||
super(ForFlow, self).__init__(module, 'for', inputs, start_pos,
|
super(ForFlow, self).__init__(module, 'for', inputs, start_pos,
|
||||||
set_stmt.used_vars)
|
set_stmt.used_vars)
|
||||||
self.set_stmt = set_stmt
|
self.set_stmt = set_stmt
|
||||||
|
set_stmt.parent = self.use_as_parent
|
||||||
self.is_list_comp = is_list_comp
|
self.is_list_comp = is_list_comp
|
||||||
|
|
||||||
def get_code(self, first_indent=False, indention=" " * 4):
|
def get_code(self, first_indent=False, indention=" " * 4):
|
||||||
@@ -819,6 +821,9 @@ class Statement(Simple):
|
|||||||
start_pos = tok.start_pos
|
start_pos = tok.start_pos
|
||||||
first = False
|
first = False
|
||||||
end_pos = tok.end_pos
|
end_pos = tok.end_pos
|
||||||
|
if isinstance(tok, ListComprehension):
|
||||||
|
# it's not possible to set it earlier
|
||||||
|
tok.parent = self
|
||||||
else:
|
else:
|
||||||
token_type, tok, start_tok_pos = tok_temp
|
token_type, tok, start_tok_pos = tok_temp
|
||||||
end_pos = start_tok_pos[0], start_tok_pos[1] + len(tok)
|
end_pos = start_tok_pos[0], start_tok_pos[1] + len(tok)
|
||||||
@@ -1169,13 +1174,13 @@ class Name(Simple):
|
|||||||
|
|
||||||
class ListComprehension(Base):
|
class ListComprehension(Base):
|
||||||
""" Helper class for list comprehensions """
|
""" Helper class for list comprehensions """
|
||||||
def __init__(self, stmt, middle, input, parent):
|
def __init__(self, stmt, middle, input):
|
||||||
self.stmt = stmt
|
self.stmt = stmt
|
||||||
self.middle = middle
|
self.middle = middle
|
||||||
self.input = input
|
self.input = input
|
||||||
for s in [stmt, middle, input]:
|
for s in [stmt, middle, input]:
|
||||||
s.parent = self
|
s.parent = self
|
||||||
self.parent = parent
|
self.parent = None
|
||||||
|
|
||||||
def get_parent_until(self, *args, **kwargs):
|
def get_parent_until(self, *args, **kwargs):
|
||||||
return Simple.get_parent_until(self, *args, **kwargs)
|
return Simple.get_parent_until(self, *args, **kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user