forked from VimPlug/jedi
some minor fixes / inits to inputs refactoring
This commit is contained in:
@@ -194,9 +194,10 @@ def check_array_additions(array):
|
||||
|
||||
def _scan_array(arr, search_name):
|
||||
""" Returns the function Call that match search_name in an Array. """
|
||||
print arr
|
||||
result = []
|
||||
for sub in arr:
|
||||
for s in sub:
|
||||
for stmt in arr:
|
||||
for s in stmt.get_commands():
|
||||
if isinstance(s, pr.Array):
|
||||
result += _scan_array(s, search_name)
|
||||
elif isinstance(s, pr.Call):
|
||||
@@ -461,8 +462,8 @@ def check_flow_information(flow, search_name, pos):
|
||||
break
|
||||
|
||||
if isinstance(flow, pr.Flow) and not result:
|
||||
if flow.command in ['if', 'while'] and len(flow.inits) == 1:
|
||||
result = check_statement_information(flow.inits[0], search_name)
|
||||
if flow.command in ['if', 'while'] and len(flow.inputs) == 1:
|
||||
result = check_statement_information(flow.inputs[0], search_name)
|
||||
return result
|
||||
|
||||
|
||||
|
||||
@@ -248,12 +248,13 @@ def find_name(scope, name_str, position=None, search_global=False,
|
||||
def handle_for_loops(loop):
|
||||
# Take the first statement (for has always only
|
||||
# one, remember `in`). And follow it.
|
||||
if not len(loop.inits):
|
||||
if not loop.inputs:
|
||||
return []
|
||||
result = get_iterator_types(follow_statement(loop.inits[0]))
|
||||
result = get_iterator_types(follow_statement(loop.inputs[0]))
|
||||
if len(loop.set_vars) > 1:
|
||||
commands = loop.set_stmt.get_commands()
|
||||
result = assign_tuples(commands, result, name_str)
|
||||
# loops with loop.set_vars > 0 only have one command
|
||||
result = assign_tuples(commands[0], result, name_str)
|
||||
return result
|
||||
|
||||
def process(name):
|
||||
|
||||
@@ -311,6 +311,8 @@ def sys_path_with_modifications(module):
|
||||
|
||||
sys_path = list(get_sys_path()) # copy
|
||||
for p in possible_stmts:
|
||||
if not isinstance(p, pr.Statement):
|
||||
continue
|
||||
commands = p.get_commands()
|
||||
assert len(commands) == 1
|
||||
call = commands[0]
|
||||
|
||||
@@ -658,8 +658,8 @@ class Parser(object):
|
||||
command = tok
|
||||
if command in ['except', 'with']:
|
||||
added_breaks.append(',')
|
||||
# multiple statements because of with
|
||||
inits = []
|
||||
# multiple inputs because of with
|
||||
inputs = []
|
||||
first = True
|
||||
while first or command == 'with' \
|
||||
and tok not in [':', '\n']:
|
||||
@@ -673,11 +673,11 @@ class Parser(object):
|
||||
statement.set_vars.append(n)
|
||||
statement.code += ',' + n.get_code()
|
||||
if statement:
|
||||
inits.append(statement)
|
||||
inputs.append(statement)
|
||||
first = False
|
||||
|
||||
if tok == ':':
|
||||
f = pr.Flow(self.module, command, inits, first_pos)
|
||||
f = pr.Flow(self.module, command, inputs, first_pos)
|
||||
if command in extended_flow:
|
||||
# the last statement has to be another part of
|
||||
# the flow statement, because a dedent releases the
|
||||
@@ -691,7 +691,7 @@ class Parser(object):
|
||||
s = self.scope.add_statement(f)
|
||||
self.scope = s
|
||||
else:
|
||||
for i in inits:
|
||||
for i in inputs:
|
||||
i.parent = use_as_parent_scope
|
||||
debug.warning('syntax err, flow started @%s',
|
||||
self.start_pos[0])
|
||||
|
||||
@@ -457,21 +457,21 @@ class Flow(Scope):
|
||||
|
||||
:param command: The flow command, if, while, else, etc.
|
||||
:type command: str
|
||||
:param inits: The initializations of a flow -> while 'statement'.
|
||||
:type inits: list(Statement)
|
||||
:param inputs: The initializations of a flow -> while 'statement'.
|
||||
:type inputs: list(Statement)
|
||||
:param start_pos: Position (line, column) of the Flow statement.
|
||||
:type start_pos: tuple(int, int)
|
||||
:param set_vars: Local variables used in the for loop (only there).
|
||||
:type set_vars: list
|
||||
"""
|
||||
def __init__(self, module, command, inits, start_pos, set_vars=None):
|
||||
def __init__(self, module, command, inputs, start_pos, set_vars=None):
|
||||
self.next = None
|
||||
self.command = command
|
||||
super(Flow, self).__init__(module, start_pos)
|
||||
self._parent = None
|
||||
# These have to be statements, because of with, which takes multiple.
|
||||
self.inits = inits
|
||||
for s in inits:
|
||||
self.inputs = inputs
|
||||
for s in inputs:
|
||||
s.parent = self.use_as_parent
|
||||
if set_vars is None:
|
||||
self.set_vars = []
|
||||
@@ -493,7 +493,7 @@ class Flow(Scope):
|
||||
|
||||
def get_code(self, first_indent=False, indention=' '):
|
||||
stmts = []
|
||||
for s in self.inits:
|
||||
for s in self.inputs:
|
||||
stmts.append(s.get_code(new_line=False))
|
||||
stmt = ', '.join(stmts)
|
||||
string = "%s %s:\n" % (self.command, stmt)
|
||||
@@ -512,7 +512,7 @@ class Flow(Scope):
|
||||
"""
|
||||
if is_internal_call:
|
||||
n = list(self.set_vars)
|
||||
for s in self.inits:
|
||||
for s in self.inputs:
|
||||
n += s.set_vars
|
||||
if self.next:
|
||||
n += self.next.get_set_vars(is_internal_call)
|
||||
@@ -541,8 +541,8 @@ class ForFlow(Flow):
|
||||
"""
|
||||
Used for the for loop, because there are two statement parts.
|
||||
"""
|
||||
def __init__(self, module, inits, start_pos, set_stmt, is_list_comp=False):
|
||||
super(ForFlow, self).__init__(module, 'for', inits, start_pos,
|
||||
def __init__(self, module, inputs, start_pos, set_stmt, is_list_comp=False):
|
||||
super(ForFlow, self).__init__(module, 'for', inputs, start_pos,
|
||||
set_stmt.used_vars)
|
||||
self.set_stmt = set_stmt
|
||||
self.is_list_comp = is_list_comp
|
||||
@@ -550,7 +550,7 @@ class ForFlow(Flow):
|
||||
def get_code(self, first_indent=False, indention=" " * 4):
|
||||
vars = ",".join(x.get_code() for x in self.set_vars)
|
||||
stmts = []
|
||||
for s in self.inits:
|
||||
for s in self.inputs:
|
||||
stmts.append(s.get_code(new_line=False))
|
||||
stmt = ', '.join(stmts)
|
||||
s = "for %s in %s:\n" % (vars, stmt)
|
||||
|
||||
Reference in New Issue
Block a user