forked from VimPlug/jedi
Statement.get_assignment_details -> get_commands (makes more sense)
This commit is contained in:
+2
-2
@@ -355,9 +355,9 @@ class Script(object):
|
|||||||
if user_stmt is None \
|
if user_stmt is None \
|
||||||
or not isinstance(user_stmt, pr.Statement):
|
or not isinstance(user_stmt, pr.Statement):
|
||||||
return None, 0
|
return None, 0
|
||||||
ass = helpers.fast_parent_copy(user_stmt.get_assignment_calls())
|
commands = helpers.fast_parent_copy(user_stmt.get_commands())
|
||||||
|
|
||||||
call, index, stop = helpers.search_function_call(ass, self.pos)
|
call, index, stop = helpers.search_function_call(commands, self.pos)
|
||||||
return call, index
|
return call, index
|
||||||
|
|
||||||
def check_cache():
|
def check_cache():
|
||||||
|
|||||||
+9
-9
@@ -133,7 +133,7 @@ def search_params(param):
|
|||||||
|
|
||||||
for stmt in possible_stmts:
|
for stmt in possible_stmts:
|
||||||
if not isinstance(stmt, pr.Import):
|
if not isinstance(stmt, pr.Import):
|
||||||
calls = _scan_array(stmt.get_assignment_calls(), func_name)
|
calls = _scan_array(stmt.get_commands(), func_name)
|
||||||
for c in calls:
|
for c in calls:
|
||||||
# no execution means that params cannot be set
|
# no execution means that params cannot be set
|
||||||
call_path = c.generate_call_path()
|
call_path = c.generate_call_path()
|
||||||
@@ -157,11 +157,11 @@ def search_params(param):
|
|||||||
|
|
||||||
# get the param name
|
# get the param name
|
||||||
if param.assignment_details:
|
if param.assignment_details:
|
||||||
arr = param.assignment_details[0][1]
|
commands = param.assignment_details[0]
|
||||||
else:
|
else:
|
||||||
arr = param.get_assignment_calls()
|
commands = param.get_commands()
|
||||||
offset = 1 if arr[0][0] in ['*', '**'] else 0
|
offset = 1 if commands[0] in ['*', '**'] else 0
|
||||||
param_name = str(arr[0][offset].name)
|
param_name = str(commands[0][offset].name)
|
||||||
|
|
||||||
# add the listener
|
# add the listener
|
||||||
listener = ParamListener()
|
listener = ParamListener()
|
||||||
@@ -303,7 +303,7 @@ def _check_array_additions(compare_array, module, is_list):
|
|||||||
if evaluate.follow_statement.push_stmt(stmt):
|
if evaluate.follow_statement.push_stmt(stmt):
|
||||||
# check recursion
|
# check recursion
|
||||||
continue
|
continue
|
||||||
res += check_calls(_scan_array(stmt.get_assignment_calls(), n), n)
|
res += check_calls(_scan_array(stmt.get_commands(), n), n)
|
||||||
evaluate.follow_statement.pop_stmt()
|
evaluate.follow_statement.pop_stmt()
|
||||||
# reset settings
|
# reset settings
|
||||||
settings.dynamic_params_for_other_modules = temp_param_add
|
settings.dynamic_params_for_other_modules = temp_param_add
|
||||||
@@ -416,7 +416,7 @@ def related_names(definitions, search_name, mods):
|
|||||||
if set(f) & set(definitions):
|
if set(f) & set(definitions):
|
||||||
names.append(api_classes.RelatedName(name_part, stmt))
|
names.append(api_classes.RelatedName(name_part, stmt))
|
||||||
else:
|
else:
|
||||||
calls = _scan_array(stmt.get_assignment_calls(), search_name)
|
calls = _scan_array(stmt.get_commands(), search_name)
|
||||||
for d in stmt.assignment_details:
|
for d in stmt.assignment_details:
|
||||||
calls += _scan_array(d[1], search_name)
|
calls += _scan_array(d[1], search_name)
|
||||||
for call in calls:
|
for call in calls:
|
||||||
@@ -462,9 +462,9 @@ def check_flow_information(flow, search_name, pos):
|
|||||||
|
|
||||||
def check_statement_information(stmt, search_name):
|
def check_statement_information(stmt, search_name):
|
||||||
try:
|
try:
|
||||||
ass = stmt.get_assignment_calls()
|
commands = stmt.get_commands()
|
||||||
try:
|
try:
|
||||||
call = ass.get_only_subelement()
|
call = commands.get_only_subelement()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
assert False
|
assert False
|
||||||
assert type(call) == pr.Call and str(call.name) == 'isinstance'
|
assert type(call) == pr.Call and str(call.name) == 'isinstance'
|
||||||
|
|||||||
+8
-7
@@ -252,8 +252,8 @@ def find_name(scope, name_str, position=None, search_global=False,
|
|||||||
return []
|
return []
|
||||||
result = get_iterator_types(follow_statement(loop.inits[0]))
|
result = get_iterator_types(follow_statement(loop.inits[0]))
|
||||||
if len(loop.set_vars) > 1:
|
if len(loop.set_vars) > 1:
|
||||||
var_arr = loop.set_stmt.get_assignment_calls()
|
commands = loop.set_stmt.get_commands()
|
||||||
result = assign_tuples(var_arr, result, name_str)
|
result = assign_tuples(commands, result, name_str)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def process(name):
|
def process(name):
|
||||||
@@ -534,11 +534,11 @@ def follow_statement(stmt, seek_name=None):
|
|||||||
:param seek_name: A string.
|
:param seek_name: A string.
|
||||||
"""
|
"""
|
||||||
debug.dbg('follow_stmt %s (%s)' % (stmt, seek_name))
|
debug.dbg('follow_stmt %s (%s)' % (stmt, seek_name))
|
||||||
call_list = stmt.get_assignment_calls()
|
commands = stmt.get_commands()
|
||||||
debug.dbg('calls: %s' % call_list)
|
debug.dbg('calls: %s' % commands)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = follow_call_list(call_list)
|
result = follow_call_list(commands)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# This is so evil! But necessary to propagate errors. The attribute
|
# This is so evil! But necessary to propagate errors. The attribute
|
||||||
# errors here must not be catched, because they shouldn't exist.
|
# errors here must not be catched, because they shouldn't exist.
|
||||||
@@ -741,8 +741,9 @@ def filter_private_variable(scope, call_scope, var_name):
|
|||||||
|
|
||||||
def goto(stmt, call_path=None):
|
def goto(stmt, call_path=None):
|
||||||
if call_path is None:
|
if call_path is None:
|
||||||
arr = stmt.get_assignment_calls()
|
commands = stmt.get_commands()
|
||||||
call = arr.get_only_subelement()
|
assert len(commands) == 1
|
||||||
|
call = commands[0]
|
||||||
call_path = list(call.generate_call_path())
|
call_path = list(call.generate_call_path())
|
||||||
|
|
||||||
scope = stmt.parent
|
scope = stmt.parent
|
||||||
|
|||||||
@@ -215,9 +215,9 @@ class InstanceElement(use_metaclass(cache.CachedMetaClass)):
|
|||||||
return self
|
return self
|
||||||
return func
|
return func
|
||||||
|
|
||||||
def get_assignment_calls(self):
|
def get_commands(self):
|
||||||
# Copy and modify the array.
|
# Copy and modify the array.
|
||||||
origin = self.var.get_assignment_calls()
|
origin = self.var.get_commands()
|
||||||
# Delete parent, because it isn't used anymore.
|
# Delete parent, because it isn't used anymore.
|
||||||
new = helpers.fast_parent_copy(origin)
|
new = helpers.fast_parent_copy(origin)
|
||||||
par = InstanceElement(self.instance, origin.parent_stmt,
|
par = InstanceElement(self.instance, origin.parent_stmt,
|
||||||
@@ -548,8 +548,8 @@ class Execution(Executable):
|
|||||||
values=[value]))
|
values=[value]))
|
||||||
key, value = next(var_arg_iterator, (None, None))
|
key, value = next(var_arg_iterator, (None, None))
|
||||||
|
|
||||||
assignments = param.get_assignment_calls().values
|
commands = param.get_commands().values
|
||||||
assignment = assignments[0]
|
assignment = commands[0]
|
||||||
keys = []
|
keys = []
|
||||||
values = []
|
values = []
|
||||||
array_type = None
|
array_type = None
|
||||||
@@ -576,7 +576,7 @@ class Execution(Executable):
|
|||||||
else:
|
else:
|
||||||
if param.assignment_details:
|
if param.assignment_details:
|
||||||
# No value: return the default values.
|
# No value: return the default values.
|
||||||
values = assignments
|
values = commands
|
||||||
else:
|
else:
|
||||||
# If there is no assignment detail, that means there is
|
# If there is no assignment detail, that means there is
|
||||||
# no assignment, just the result. Therefore nothing has
|
# no assignment, just the result. Therefore nothing has
|
||||||
@@ -774,7 +774,7 @@ class Array(use_metaclass(cache.CachedMetaClass, pr.Base)):
|
|||||||
def get_index_types(self, index_arr=None):
|
def get_index_types(self, index_arr=None):
|
||||||
""" Get the types of a specific index or all, if not given """
|
""" Get the types of a specific index or all, if not given """
|
||||||
if index_arr is not None:
|
if index_arr is not None:
|
||||||
if index_arr and [x for x in index_arr if ':' in x.get_assignment_calls()]:
|
if index_arr and [x for x in index_arr if ':' in x.get_commands()]:
|
||||||
# array slicing
|
# array slicing
|
||||||
return [self]
|
return [self]
|
||||||
|
|
||||||
|
|||||||
+3
-4
@@ -311,10 +311,9 @@ 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:
|
||||||
try:
|
commands = p.get_commands()
|
||||||
call = p.get_assignment_calls().get_only_subelement()
|
assert len(commands) == 1
|
||||||
except AttributeError:
|
call = commands[0]
|
||||||
continue
|
|
||||||
n = call.name
|
n = call.name
|
||||||
if not isinstance(n, pr.Name) or len(n.names) != 3:
|
if not isinstance(n, pr.Name) or len(n.names) != 3:
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -658,7 +658,7 @@ class Statement(Simple):
|
|||||||
:type start_pos: tuple(int, int)
|
:type start_pos: tuple(int, int)
|
||||||
"""
|
"""
|
||||||
__slots__ = ('used_funcs', 'code', 'token_list', 'used_vars',
|
__slots__ = ('used_funcs', 'code', 'token_list', 'used_vars',
|
||||||
'set_vars', '_assignment_calls', '_assignment_details')
|
'set_vars', '_commands', '_assignment_details')
|
||||||
|
|
||||||
def __init__(self, module, code, set_vars, used_funcs, used_vars,
|
def __init__(self, module, code, set_vars, used_funcs, used_vars,
|
||||||
token_list, start_pos, end_pos, parent=None):
|
token_list, start_pos, end_pos, parent=None):
|
||||||
@@ -674,7 +674,7 @@ class Statement(Simple):
|
|||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
|
||||||
# cache
|
# cache
|
||||||
self._assignment_calls = None
|
self._commands = None
|
||||||
self._assignment_details = None
|
self._assignment_details = None
|
||||||
# this is important for other scripts
|
# this is important for other scripts
|
||||||
|
|
||||||
@@ -711,7 +711,7 @@ class Statement(Simple):
|
|||||||
|
|
||||||
def get_code(self, new_line=True):
|
def get_code(self, new_line=True):
|
||||||
code = ''
|
code = ''
|
||||||
for c in self.get_assignment_calls():
|
for c in self.get_commands():
|
||||||
if isinstance(c, Call):
|
if isinstance(c, Call):
|
||||||
code += c.get_code()
|
code += c.get_code()
|
||||||
else:
|
else:
|
||||||
@@ -731,7 +731,7 @@ class Statement(Simple):
|
|||||||
return str(self.token_list[0]) == "global"
|
return str(self.token_list[0]) == "global"
|
||||||
|
|
||||||
def get_command(self, index):
|
def get_command(self, index):
|
||||||
commands = self.get_assignment_calls()
|
commands = self.get_commands()
|
||||||
try:
|
try:
|
||||||
return commands[index]
|
return commands[index]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@@ -739,16 +739,16 @@ class Statement(Simple):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def assignment_details(self):
|
def assignment_details(self):
|
||||||
if self._assignment_calls is None:
|
if self._commands is None:
|
||||||
# parse statement and therefore get the assignment details.
|
# parse statement and therefore get the assignment details.
|
||||||
self._parse_statement()
|
self._parse_statement()
|
||||||
return self._assignment_details
|
return self._assignment_details
|
||||||
|
|
||||||
def get_assignment_calls(self):
|
def get_commands(self):
|
||||||
if self._assignment_calls is None:
|
if self._commands is None:
|
||||||
result = self._parse_statement()
|
result = self._parse_statement()
|
||||||
self._assignment_calls = result
|
self._commands = result
|
||||||
return self._assignment_calls
|
return self._commands
|
||||||
|
|
||||||
def _parse_statement(self):
|
def _parse_statement(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
+6
-7
@@ -113,8 +113,7 @@ def extract(script, new_name):
|
|||||||
if user_stmt:
|
if user_stmt:
|
||||||
pos = script.pos
|
pos = script.pos
|
||||||
line_index = pos[0] - 1
|
line_index = pos[0] - 1
|
||||||
arr, index = helpers.array_for_pos(user_stmt.get_assignment_calls(),
|
arr, index = helpers.array_for_pos(user_stmt.get_commands(), pos)
|
||||||
pos)
|
|
||||||
if arr:
|
if arr:
|
||||||
s = arr.start_pos[0], arr.start_pos[1] + 1
|
s = arr.start_pos[0], arr.start_pos[1] + 1
|
||||||
positions = [s] + arr.arr_el_pos + [arr.end_pos]
|
positions = [s] + arr.arr_el_pos + [arr.end_pos]
|
||||||
@@ -178,16 +177,16 @@ def inline(script):
|
|||||||
if not stmt.start_pos <= r.start_pos <= stmt.end_pos]
|
if not stmt.start_pos <= r.start_pos <= stmt.end_pos]
|
||||||
inlines = sorted(inlines, key=lambda x: (x.module_path, x.start_pos),
|
inlines = sorted(inlines, key=lambda x: (x.module_path, x.start_pos),
|
||||||
reverse=True)
|
reverse=True)
|
||||||
ass = stmt.get_assignment_calls()
|
commands = stmt.get_commands()
|
||||||
# don't allow multiline refactorings for now.
|
# don't allow multiline refactorings for now.
|
||||||
assert ass.start_pos[0] == ass.end_pos[0]
|
assert commands.start_pos[0] == commands.end_pos[0]
|
||||||
index = ass.start_pos[0] - 1
|
index = commands.start_pos[0] - 1
|
||||||
|
|
||||||
line = new_lines[index]
|
line = new_lines[index]
|
||||||
replace_str = line[ass.start_pos[1]:ass.end_pos[1] + 1]
|
replace_str = line[commands.start_pos[1]:commands.end_pos[1] + 1]
|
||||||
replace_str = replace_str.strip()
|
replace_str = replace_str.strip()
|
||||||
# tuples need parentheses
|
# tuples need parentheses
|
||||||
if len(ass.values) > 1:
|
if len(commands.values) > 1:
|
||||||
replace_str = '(%s)' % replace_str
|
replace_str = '(%s)' % replace_str
|
||||||
|
|
||||||
# if it's the only assignment, remove the statement
|
# if it's the only assignment, remove the statement
|
||||||
|
|||||||
Reference in New Issue
Block a user