1
0
forked from VimPlug/jedi

Statement.get_assignment_details -> get_commands (makes more sense)

This commit is contained in:
David Halter
2013-02-08 16:19:05 +01:00
parent d6257fffc8
commit 70f07320aa
7 changed files with 43 additions and 44 deletions

View File

@@ -355,9 +355,9 @@ class Script(object):
if user_stmt is None \
or not isinstance(user_stmt, pr.Statement):
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
def check_cache():

View File

@@ -133,7 +133,7 @@ def search_params(param):
for stmt in possible_stmts:
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:
# no execution means that params cannot be set
call_path = c.generate_call_path()
@@ -157,11 +157,11 @@ def search_params(param):
# get the param name
if param.assignment_details:
arr = param.assignment_details[0][1]
commands = param.assignment_details[0]
else:
arr = param.get_assignment_calls()
offset = 1 if arr[0][0] in ['*', '**'] else 0
param_name = str(arr[0][offset].name)
commands = param.get_commands()
offset = 1 if commands[0] in ['*', '**'] else 0
param_name = str(commands[0][offset].name)
# add the listener
listener = ParamListener()
@@ -303,7 +303,7 @@ def _check_array_additions(compare_array, module, is_list):
if evaluate.follow_statement.push_stmt(stmt):
# check recursion
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()
# reset settings
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):
names.append(api_classes.RelatedName(name_part, stmt))
else:
calls = _scan_array(stmt.get_assignment_calls(), search_name)
calls = _scan_array(stmt.get_commands(), search_name)
for d in stmt.assignment_details:
calls += _scan_array(d[1], search_name)
for call in calls:
@@ -462,9 +462,9 @@ def check_flow_information(flow, search_name, pos):
def check_statement_information(stmt, search_name):
try:
ass = stmt.get_assignment_calls()
commands = stmt.get_commands()
try:
call = ass.get_only_subelement()
call = commands.get_only_subelement()
except AttributeError:
assert False
assert type(call) == pr.Call and str(call.name) == 'isinstance'

View File

@@ -252,8 +252,8 @@ def find_name(scope, name_str, position=None, search_global=False,
return []
result = get_iterator_types(follow_statement(loop.inits[0]))
if len(loop.set_vars) > 1:
var_arr = loop.set_stmt.get_assignment_calls()
result = assign_tuples(var_arr, result, name_str)
commands = loop.set_stmt.get_commands()
result = assign_tuples(commands, result, name_str)
return result
def process(name):
@@ -534,11 +534,11 @@ def follow_statement(stmt, seek_name=None):
:param seek_name: A string.
"""
debug.dbg('follow_stmt %s (%s)' % (stmt, seek_name))
call_list = stmt.get_assignment_calls()
debug.dbg('calls: %s' % call_list)
commands = stmt.get_commands()
debug.dbg('calls: %s' % commands)
try:
result = follow_call_list(call_list)
result = follow_call_list(commands)
except AttributeError:
# This is so evil! But necessary to propagate errors. The attribute
# 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):
if call_path is None:
arr = stmt.get_assignment_calls()
call = arr.get_only_subelement()
commands = stmt.get_commands()
assert len(commands) == 1
call = commands[0]
call_path = list(call.generate_call_path())
scope = stmt.parent

View File

@@ -215,9 +215,9 @@ class InstanceElement(use_metaclass(cache.CachedMetaClass)):
return self
return func
def get_assignment_calls(self):
def get_commands(self):
# Copy and modify the array.
origin = self.var.get_assignment_calls()
origin = self.var.get_commands()
# Delete parent, because it isn't used anymore.
new = helpers.fast_parent_copy(origin)
par = InstanceElement(self.instance, origin.parent_stmt,
@@ -548,8 +548,8 @@ class Execution(Executable):
values=[value]))
key, value = next(var_arg_iterator, (None, None))
assignments = param.get_assignment_calls().values
assignment = assignments[0]
commands = param.get_commands().values
assignment = commands[0]
keys = []
values = []
array_type = None
@@ -576,7 +576,7 @@ class Execution(Executable):
else:
if param.assignment_details:
# No value: return the default values.
values = assignments
values = commands
else:
# If there is no assignment detail, that means there is
# 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):
""" Get the types of a specific index or all, if not given """
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
return [self]

View File

@@ -311,10 +311,9 @@ def sys_path_with_modifications(module):
sys_path = list(get_sys_path()) # copy
for p in possible_stmts:
try:
call = p.get_assignment_calls().get_only_subelement()
except AttributeError:
continue
commands = p.get_commands()
assert len(commands) == 1
call = commands[0]
n = call.name
if not isinstance(n, pr.Name) or len(n.names) != 3:
continue

View File

@@ -658,7 +658,7 @@ class Statement(Simple):
:type start_pos: tuple(int, int)
"""
__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,
token_list, start_pos, end_pos, parent=None):
@@ -674,7 +674,7 @@ class Statement(Simple):
self.parent = parent
# cache
self._assignment_calls = None
self._commands = None
self._assignment_details = None
# this is important for other scripts
@@ -711,7 +711,7 @@ class Statement(Simple):
def get_code(self, new_line=True):
code = ''
for c in self.get_assignment_calls():
for c in self.get_commands():
if isinstance(c, Call):
code += c.get_code()
else:
@@ -731,7 +731,7 @@ class Statement(Simple):
return str(self.token_list[0]) == "global"
def get_command(self, index):
commands = self.get_assignment_calls()
commands = self.get_commands()
try:
return commands[index]
except IndexError:
@@ -739,16 +739,16 @@ class Statement(Simple):
@property
def assignment_details(self):
if self._assignment_calls is None:
if self._commands is None:
# parse statement and therefore get the assignment details.
self._parse_statement()
return self._assignment_details
def get_assignment_calls(self):
if self._assignment_calls is None:
def get_commands(self):
if self._commands is None:
result = self._parse_statement()
self._assignment_calls = result
return self._assignment_calls
self._commands = result
return self._commands
def _parse_statement(self):
"""

View File

@@ -113,8 +113,7 @@ def extract(script, new_name):
if user_stmt:
pos = script.pos
line_index = pos[0] - 1
arr, index = helpers.array_for_pos(user_stmt.get_assignment_calls(),
pos)
arr, index = helpers.array_for_pos(user_stmt.get_commands(), pos)
if arr:
s = arr.start_pos[0], arr.start_pos[1] + 1
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]
inlines = sorted(inlines, key=lambda x: (x.module_path, x.start_pos),
reverse=True)
ass = stmt.get_assignment_calls()
commands = stmt.get_commands()
# don't allow multiline refactorings for now.
assert ass.start_pos[0] == ass.end_pos[0]
index = ass.start_pos[0] - 1
assert commands.start_pos[0] == commands.end_pos[0]
index = commands.start_pos[0] - 1
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()
# tuples need parentheses
if len(ass.values) > 1:
if len(commands.values) > 1:
replace_str = '(%s)' % replace_str
# if it's the only assignment, remove the statement