1
0
forked from VimPlug/jedi

expression_list instead of commands in more places

This commit is contained in:
Dave Halter
2013-12-27 14:31:03 +01:00
parent 4af92b166a
commit 7347c46502
6 changed files with 37 additions and 37 deletions

View File

@@ -312,9 +312,9 @@ class Evaluator(object):
return [] return []
result = get_iterator_types(self.eval_statement(loop.inputs[0])) result = get_iterator_types(self.eval_statement(loop.inputs[0]))
if len(loop.set_vars) > 1: if len(loop.set_vars) > 1:
commands = loop.set_stmt.expression_list() expression_list = loop.set_stmt.expression_list()
# loops with loop.set_vars > 0 only have one command # loops with loop.set_vars > 0 only have one command
result = assign_tuples(commands[0], result, name_str) result = assign_tuples(expression_list[0], result, name_str)
return result return result
def process(name): def process(name):
@@ -497,8 +497,8 @@ class Evaluator(object):
# variables. # variables.
if len(stmt.get_set_vars()) > 1 and seek_name and stmt.assignment_details: if len(stmt.get_set_vars()) > 1 and seek_name and stmt.assignment_details:
new_result = [] new_result = []
for ass_commands, op in stmt.assignment_details: for ass_expression_list, op in stmt.assignment_details:
new_result += find_assignments(ass_commands[0], result, seek_name) new_result += find_assignments(ass_expression_list[0], result, seek_name)
result = new_result result = new_result
return set(result) return set(result)
@@ -669,12 +669,12 @@ class Evaluator(object):
def goto(self, stmt, call_path=None): def goto(self, stmt, call_path=None):
if call_path is None: if call_path is None:
commands = stmt.expression_list() expression_list = stmt.expression_list()
if len(commands) == 0: if len(expression_list) == 0:
return [], '' return [], ''
# Only the first command is important, the rest should basically not # Only the first command is important, the rest should basically not
# happen except in broken code (e.g. docstrings that aren't code). # happen except in broken code (e.g. docstrings that aren't code).
call = commands[0] call = expression_list[0]
if isinstance(call, (str, unicode)): if isinstance(call, (str, unicode)):
call_path = [call] call_path = [call]
else: else:

View File

@@ -209,11 +209,11 @@ def search_params(evaluator, param):
# get the param name # get the param name
if param.assignment_details: if param.assignment_details:
# first assignment details, others would be a syntax error # first assignment details, others would be a syntax error
commands, op = param.assignment_details[0] expression_list, op = param.assignment_details[0]
else: else:
commands = param.expression_list() expression_list = param.expression_list()
offset = 1 if commands[0] in ['*', '**'] else 0 offset = 1 if expression_list[0] in ['*', '**'] else 0
param_name = str(commands[offset].name) param_name = str(expression_list[offset].name)
# add the listener # add the listener
listener = ParamListener() listener = ParamListener()
@@ -259,8 +259,8 @@ def _scan_statement(stmt, search_name, assignment_details=False):
check = list(stmt.expression_list()) check = list(stmt.expression_list())
if assignment_details: if assignment_details:
for commands, op in stmt.assignment_details: for expression_list, op in stmt.assignment_details:
check += commands check += expression_list
result = [] result = []
for c in check: for c in check:
@@ -465,10 +465,10 @@ def check_flow_information(evaluator, flow, search_name, pos):
def _check_isinstance_type(evaluator, stmt, search_name): def _check_isinstance_type(evaluator, stmt, search_name):
from jedi.evaluate import representation as er from jedi.evaluate import representation as er
try: try:
commands = stmt.expression_list() expression_list = stmt.expression_list()
# this might be removed if we analyze and, etc # this might be removed if we analyze and, etc
assert len(commands) == 1 assert len(expression_list) == 1
call = commands[0] call = expression_list[0]
assert isinstance(call, pr.Call) and str(call.name) == 'isinstance' assert isinstance(call, pr.Call) and str(call.name) == 'isinstance'
assert bool(call.execution) assert bool(call.execution)

View File

@@ -594,12 +594,12 @@ class Execution(Executable):
values=[value])) values=[value]))
key, value = next(var_arg_iterator, (None, None)) key, value = next(var_arg_iterator, (None, None))
commands = param.expression_list() expression_list = param.expression_list()
keys = [] keys = []
values = [] values = []
array_type = None array_type = None
ignore_creation = False ignore_creation = False
if commands[0] == '*': if expression_list[0] == '*':
# *args param # *args param
array_type = pr.Array.TUPLE array_type = pr.Array.TUPLE
if value: if value:
@@ -610,7 +610,7 @@ class Execution(Executable):
var_arg_iterator.push_back((key, value)) var_arg_iterator.push_back((key, value))
break break
values.append(value) values.append(value)
elif commands[0] == '**': elif expression_list[0] == '**':
# **kwargs param # **kwargs param
array_type = pr.Array.DICT array_type = pr.Array.DICT
if non_matching_keys: if non_matching_keys:
@@ -633,7 +633,7 @@ class Execution(Executable):
# Just ignore all the params that are without a key, after one # Just ignore all the params that are without a key, after one
# keyword argument was set. # keyword argument was set.
if not ignore_creation and (not keys_only or commands[0] == '**'): if not ignore_creation and (not keys_only or expression_list[0] == '**'):
keys_used.add(str(key)) keys_used.add(str(key))
result.append(gen_param_name_copy(param, keys=keys, result.append(gen_param_name_copy(param, keys=keys,
values=values, array_type=array_type)) values=values, array_type=array_type))
@@ -663,11 +663,11 @@ class Execution(Executable):
stmt._expression_list = [old] stmt._expression_list = [old]
# *args # *args
commands = stmt.expression_list() expression_list = stmt.expression_list()
if not len(commands): if not len(expression_list):
continue continue
if commands[0] == '*': if expression_list[0] == '*':
arrays = self._evaluator.eval_expression_list(commands[1:]) arrays = self._evaluator.eval_expression_list(expression_list[1:])
# *args must be some sort of an array, otherwise -> ignore # *args must be some sort of an array, otherwise -> ignore
for array in arrays: for array in arrays:
@@ -678,8 +678,8 @@ class Execution(Executable):
for field_stmt in array.iter_content(): for field_stmt in array.iter_content():
yield None, helpers.FakeStatement(field_stmt) yield None, helpers.FakeStatement(field_stmt)
# **kwargs # **kwargs
elif commands[0] == '**': elif expression_list[0] == '**':
arrays = self._evaluator.eval_expression_list(commands[1:]) arrays = self._evaluator.eval_expression_list(expression_list[1:])
for array in arrays: for array in arrays:
if isinstance(array, Array): if isinstance(array, Array):
for key_stmt, value_stmt in array.items(): for key_stmt, value_stmt in array.items():
@@ -868,10 +868,10 @@ class Array(use_metaclass(CachedMetaClass, pr.Base, Iterable)):
index = None index = None
for i, key_statement in enumerate(self._array.keys): for i, key_statement in enumerate(self._array.keys):
# Because we only want the key to be a string. # Because we only want the key to be a string.
key_commands = key_statement.expression_list() key_expression_list = key_statement.expression_list()
if len(key_commands) != 1: # cannot deal with complex strings if len(key_expression_list) != 1: # cannot deal with complex strings
continue continue
key = key_commands[0] key = key_expression_list[0]
if isinstance(key, pr.String): if isinstance(key, pr.String):
str_key = key.value str_key = key.value
elif isinstance(key, pr.Name): elif isinstance(key, pr.Name):

View File

@@ -320,11 +320,11 @@ def sys_path_with_modifications(module):
for p in possible_stmts: for p in possible_stmts:
if not isinstance(p, pr.Statement): if not isinstance(p, pr.Statement):
continue continue
commands = p.expression_list() expression_list = p.expression_list()
# sys.path command is just one thing. # sys.path command is just one thing.
if len(commands) != 1 or not isinstance(commands[0], pr.Call): if len(expression_list) != 1 or not isinstance(expression_list[0], pr.Call):
continue continue
call = commands[0] call = expression_list[0]
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

View File

@@ -1104,7 +1104,7 @@ class Statement(Simple):
if result and isinstance(result[-1], StatementElement): if result and isinstance(result[-1], StatementElement):
is_chain = True is_chain = True
elif tok == ',': # implies a tuple elif tok == ',': # implies a tuple
# commands is now an array not a statement anymore # expression is now an array not a statement anymore
t = result[0] t = result[0]
start_pos = t[2] if isinstance(t, tuple) else t.start_pos start_pos = t[2] if isinstance(t, tuple) else t.start_pos

View File

@@ -176,17 +176,17 @@ def inline(script):
if not stmt.start_pos <= (r.line, r.column) <= stmt.end_pos] if not stmt.start_pos <= (r.line, r.column) <= stmt.end_pos]
inlines = sorted(inlines, key=lambda x: (x.module_path, x.line, x.column), inlines = sorted(inlines, key=lambda x: (x.module_path, x.line, x.column),
reverse=True) reverse=True)
commands = stmt.expression_list() expression_list = stmt.expression_list()
# don't allow multiline refactorings for now. # don't allow multiline refactorings for now.
assert stmt.start_pos[0] == stmt.end_pos[0] assert stmt.start_pos[0] == stmt.end_pos[0]
index = stmt.start_pos[0] - 1 index = stmt.start_pos[0] - 1
line = new_lines[index] line = new_lines[index]
replace_str = line[commands[0].start_pos[1]:stmt.end_pos[1] + 1] replace_str = line[expression_list[0].start_pos[1]:stmt.end_pos[1] + 1]
replace_str = replace_str.strip() replace_str = replace_str.strip()
# tuples need parentheses # tuples need parentheses
if commands and isinstance(commands[0], pr.Array): if expression_list and isinstance(expression_list[0], pr.Array):
arr = commands[0] arr = expression_list[0]
if replace_str[0] not in ['(', '[', '{'] and len(arr) > 1: if replace_str[0] not in ['(', '[', '{'] and len(arr) > 1:
replace_str = '(%s)' % replace_str replace_str = '(%s)' % replace_str