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