From 7347c465022c19f641cbc72dcd1c7a96996c45ad Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 27 Dec 2013 14:31:03 +0100 Subject: [PATCH] expression_list instead of commands in more places --- jedi/evaluate/__init__.py | 14 +++++++------- jedi/evaluate/dynamic.py | 18 +++++++++--------- jedi/evaluate/representation.py | 26 +++++++++++++------------- jedi/modules.py | 6 +++--- jedi/parser/representation.py | 2 +- jedi/refactoring.py | 8 ++++---- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index 4b5be662..d98f1202 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -312,9 +312,9 @@ class Evaluator(object): return [] result = get_iterator_types(self.eval_statement(loop.inputs[0])) 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 - result = assign_tuples(commands[0], result, name_str) + result = assign_tuples(expression_list[0], result, name_str) return result def process(name): @@ -497,8 +497,8 @@ class Evaluator(object): # variables. if len(stmt.get_set_vars()) > 1 and seek_name and stmt.assignment_details: new_result = [] - for ass_commands, op in stmt.assignment_details: - new_result += find_assignments(ass_commands[0], result, seek_name) + for ass_expression_list, op in stmt.assignment_details: + new_result += find_assignments(ass_expression_list[0], result, seek_name) result = new_result return set(result) @@ -669,12 +669,12 @@ class Evaluator(object): def goto(self, stmt, call_path=None): if call_path is None: - commands = stmt.expression_list() - if len(commands) == 0: + expression_list = stmt.expression_list() + if len(expression_list) == 0: return [], '' # Only the first command is important, the rest should basically not # happen except in broken code (e.g. docstrings that aren't code). - call = commands[0] + call = expression_list[0] if isinstance(call, (str, unicode)): call_path = [call] else: diff --git a/jedi/evaluate/dynamic.py b/jedi/evaluate/dynamic.py index defc5be6..a332e6ba 100644 --- a/jedi/evaluate/dynamic.py +++ b/jedi/evaluate/dynamic.py @@ -209,11 +209,11 @@ def search_params(evaluator, param): # get the param name if param.assignment_details: # first assignment details, others would be a syntax error - commands, op = param.assignment_details[0] + expression_list, op = param.assignment_details[0] else: - commands = param.expression_list() - offset = 1 if commands[0] in ['*', '**'] else 0 - param_name = str(commands[offset].name) + expression_list = param.expression_list() + offset = 1 if expression_list[0] in ['*', '**'] else 0 + param_name = str(expression_list[offset].name) # add the listener listener = ParamListener() @@ -259,8 +259,8 @@ def _scan_statement(stmt, search_name, assignment_details=False): check = list(stmt.expression_list()) if assignment_details: - for commands, op in stmt.assignment_details: - check += commands + for expression_list, op in stmt.assignment_details: + check += expression_list result = [] 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): from jedi.evaluate import representation as er try: - commands = stmt.expression_list() + expression_list = stmt.expression_list() # this might be removed if we analyze and, etc - assert len(commands) == 1 - call = commands[0] + assert len(expression_list) == 1 + call = expression_list[0] assert isinstance(call, pr.Call) and str(call.name) == 'isinstance' assert bool(call.execution) diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index e564ef8c..1c949d05 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -594,12 +594,12 @@ class Execution(Executable): values=[value])) key, value = next(var_arg_iterator, (None, None)) - commands = param.expression_list() + expression_list = param.expression_list() keys = [] values = [] array_type = None ignore_creation = False - if commands[0] == '*': + if expression_list[0] == '*': # *args param array_type = pr.Array.TUPLE if value: @@ -610,7 +610,7 @@ class Execution(Executable): var_arg_iterator.push_back((key, value)) break values.append(value) - elif commands[0] == '**': + elif expression_list[0] == '**': # **kwargs param array_type = pr.Array.DICT if non_matching_keys: @@ -633,7 +633,7 @@ class Execution(Executable): # Just ignore all the params that are without a key, after one # 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)) result.append(gen_param_name_copy(param, keys=keys, values=values, array_type=array_type)) @@ -663,11 +663,11 @@ class Execution(Executable): stmt._expression_list = [old] # *args - commands = stmt.expression_list() - if not len(commands): + expression_list = stmt.expression_list() + if not len(expression_list): continue - if commands[0] == '*': - arrays = self._evaluator.eval_expression_list(commands[1:]) + if expression_list[0] == '*': + arrays = self._evaluator.eval_expression_list(expression_list[1:]) # *args must be some sort of an array, otherwise -> ignore for array in arrays: @@ -678,8 +678,8 @@ class Execution(Executable): for field_stmt in array.iter_content(): yield None, helpers.FakeStatement(field_stmt) # **kwargs - elif commands[0] == '**': - arrays = self._evaluator.eval_expression_list(commands[1:]) + elif expression_list[0] == '**': + arrays = self._evaluator.eval_expression_list(expression_list[1:]) for array in arrays: if isinstance(array, Array): for key_stmt, value_stmt in array.items(): @@ -868,10 +868,10 @@ class Array(use_metaclass(CachedMetaClass, pr.Base, Iterable)): index = None for i, key_statement in enumerate(self._array.keys): # Because we only want the key to be a string. - key_commands = key_statement.expression_list() - if len(key_commands) != 1: # cannot deal with complex strings + key_expression_list = key_statement.expression_list() + if len(key_expression_list) != 1: # cannot deal with complex strings continue - key = key_commands[0] + key = key_expression_list[0] if isinstance(key, pr.String): str_key = key.value elif isinstance(key, pr.Name): diff --git a/jedi/modules.py b/jedi/modules.py index 686fbb17..594c9d80 100644 --- a/jedi/modules.py +++ b/jedi/modules.py @@ -320,11 +320,11 @@ def sys_path_with_modifications(module): for p in possible_stmts: if not isinstance(p, pr.Statement): continue - commands = p.expression_list() + expression_list = p.expression_list() # 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 - call = commands[0] + call = expression_list[0] n = call.name if not isinstance(n, pr.Name) or len(n.names) != 3: continue diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index ab8dfb8b..433c9042 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -1104,7 +1104,7 @@ class Statement(Simple): if result and isinstance(result[-1], StatementElement): is_chain = True 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] start_pos = t[2] if isinstance(t, tuple) else t.start_pos diff --git a/jedi/refactoring.py b/jedi/refactoring.py index 3918420c..4952cfd1 100644 --- a/jedi/refactoring.py +++ b/jedi/refactoring.py @@ -176,17 +176,17 @@ def inline(script): 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), reverse=True) - commands = stmt.expression_list() + expression_list = stmt.expression_list() # don't allow multiline refactorings for now. assert stmt.start_pos[0] == stmt.end_pos[0] index = stmt.start_pos[0] - 1 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() # tuples need parentheses - if commands and isinstance(commands[0], pr.Array): - arr = commands[0] + if expression_list and isinstance(expression_list[0], pr.Array): + arr = expression_list[0] if replace_str[0] not in ['(', '[', '{'] and len(arr) > 1: replace_str = '(%s)' % replace_str