diff --git a/jedi/api.py b/jedi/api.py index 12935703..19dca909 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -441,7 +441,7 @@ class Script(object): defs, search_name = self._evaluator.goto(stmt) definitions = follow_inexistent_imports(defs) if isinstance(user_stmt, pr.Statement): - c = user_stmt.get_commands() + c = user_stmt.expression_list() if c and not isinstance(c[0], (str, unicode)) \ and c[0].start_pos > self._pos \ and not re.search(r'\.\w+$', goto_path): @@ -466,7 +466,7 @@ class Script(object): user_stmt = self._user_stmt() definitions, search_name = self._goto(add_import_name=True) if isinstance(user_stmt, pr.Statement): - c = user_stmt.get_commands()[0] + c = user_stmt.expression_list()[0] if not isinstance(c, unicode) and self._pos < c.start_pos: # the search_name might be before `=` definitions = [v for v in user_stmt.get_set_vars() diff --git a/jedi/cache.py b/jedi/cache.py index 51a5807a..806575b7 100644 --- a/jedi/cache.py +++ b/jedi/cache.py @@ -174,7 +174,7 @@ def save_module(path, name, parser, pickling=True): class _ModulePickling(object): - version = 6 + version = 7 """ Version number (integer) for file system cache. diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index 4b12d9e3..4b5be662 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -30,7 +30,7 @@ To *visualize* this (simplified): - ``eval_statement`` - ```` - Unpacking of the statement into ``[[]]`` -- ``follow_call_list``, calls ``eval_call`` with ```` +- ``eval_expression_list``, calls ``eval_call`` with ```` - ``eval_call`` - searches the ``datetime`` name within the module. This is exactly where it starts to get complicated. Now recursions start to @@ -264,7 +264,7 @@ class Evaluator(object): if not r.is_generated: res_new += dynamic.search_params(self, r) if not res_new: - c = r.get_commands()[0] + c = r.expression_list()[0] if c in ('*', '**'): t = 'tuple' if c == '*' else 'dict' res_new = [er.Instance( @@ -312,7 +312,7 @@ class Evaluator(object): return [] result = get_iterator_types(self.eval_statement(loop.inputs[0])) if len(loop.set_vars) > 1: - commands = loop.set_stmt.get_commands() + commands = loop.set_stmt.expression_list() # loops with loop.set_vars > 0 only have one command result = assign_tuples(commands[0], result, name_str) return result @@ -489,9 +489,9 @@ class Evaluator(object): :param seek_name: A string. """ debug.dbg('eval_statement %s (%s)' % (stmt, seek_name)) - commands = stmt.get_commands() + expression_list = stmt.expression_list() - result = self.follow_call_list(commands) + result = self.eval_expression_list(expression_list) # Assignment checking is only important if the statement defines multiple # variables. @@ -503,9 +503,9 @@ class Evaluator(object): return set(result) @common.rethrow_uncaught - def follow_call_list(self, call_list, follow_array=False): + def eval_expression_list(self, expression_list, follow_array=False): """ - `call_list` can be either `pr.Array` or `list of list`. + `expression_list` can be either `pr.Array` or `list of list`. It is used to evaluate a two dimensional object, that has calls, arrays and operators in it. """ @@ -525,9 +525,9 @@ class Evaluator(object): loop = evaluate_list_comprehension(nested_lc, loop) return loop - debug.dbg('follow_call_list: %s' % call_list) + debug.dbg('eval_expression_list: %s' % expression_list) result = [] - calls_iterator = iter(call_list) + calls_iterator = iter(expression_list) for call in calls_iterator: if pr.Array.is_type(call, pr.Array.NOARRAY): r = list(itertools.chain.from_iterable(self.eval_statement(s) @@ -630,7 +630,7 @@ class Evaluator(object): foo.bar.baz `follow_path` is only responsible for completing `.bar.baz`, the rest is - done in the `eval_call` function. + done in the `follow_call` function. """ # current is either an Array or a Scope. try: @@ -669,7 +669,7 @@ class Evaluator(object): def goto(self, stmt, call_path=None): if call_path is None: - commands = stmt.get_commands() + commands = stmt.expression_list() if len(commands) == 0: return [], '' # Only the first command is important, the rest should basically not @@ -793,7 +793,7 @@ def assign_tuples(tup, results, seek_name): for i, stmt in enumerate(tup): # Used in assignments. There is just one call and no other things, # therefore we can just assume, that the first part is important. - command = stmt.get_commands()[0] + command = stmt.expression_list()[0] if tup.type == pr.Array.NOARRAY: diff --git a/jedi/evaluate/dynamic.py b/jedi/evaluate/dynamic.py index d648a006..defc5be6 100644 --- a/jedi/evaluate/dynamic.py +++ b/jedi/evaluate/dynamic.py @@ -211,7 +211,7 @@ def search_params(evaluator, param): # first assignment details, others would be a syntax error commands, op = param.assignment_details[0] else: - commands = param.get_commands() + commands = param.expression_list() offset = 1 if commands[0] in ['*', '**'] else 0 param_name = str(commands[offset].name) @@ -257,7 +257,7 @@ def _scan_statement(stmt, search_name, assignment_details=False): result += _scan_statement(stmt, search_name) return result - check = list(stmt.get_commands()) + check = list(stmt.expression_list()) if assignment_details: for commands, op in stmt.assignment_details: check += commands @@ -465,7 +465,7 @@ 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.get_commands() + commands = stmt.expression_list() # this might be removed if we analyze and, etc assert len(commands) == 1 call = commands[0] @@ -475,7 +475,7 @@ def _check_isinstance_type(evaluator, stmt, search_name): # isinstance check isinst = call.execution.values assert len(isinst) == 2 # has two params - obj, classes = [statement.get_commands() for statement in isinst] + obj, classes = [statement.expression_list() for statement in isinst] assert len(obj) == 1 assert len(classes) == 1 assert isinstance(obj[0], pr.Call) diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index 19077014..e564ef8c 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -227,11 +227,11 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)): return self return func - def get_commands(self): + def expression_list(self): # Copy and modify the array. return [InstanceElement(self.instance._evaluator, self.instance, command, self.is_class_var) if not isinstance(command, unicode) else command - for command in self.var.get_commands()] + for command in self.var.expression_list()] def __iter__(self): for el in self.var.__iter__(): @@ -545,12 +545,12 @@ class Execution(Executable): key_stmts = [] for key in keys: stmt = pr.Statement(self._sub_module, [], start_pos, None) - stmt._commands = [key] + stmt._expression_list = [key] key_stmts.append(stmt) arr.keys = key_stmts arr.type = array_type - new_param._commands = [arr] + new_param._expression_list = [arr] name = copy.copy(param.get_name()) name.parent = new_param @@ -594,7 +594,7 @@ class Execution(Executable): values=[value])) key, value = next(var_arg_iterator, (None, None)) - commands = param.get_commands() + commands = param.expression_list() keys = [] values = [] array_type = None @@ -660,14 +660,14 @@ class Execution(Executable): # generate a statement if it's not already one. module = builtin.Builtin.scope stmt = pr.Statement(module, [], (0, 0), None) - stmt._commands = [old] + stmt._expression_list = [old] # *args - commands = stmt.get_commands() + commands = stmt.expression_list() if not len(commands): continue if commands[0] == '*': - arrays = self._evaluator.follow_call_list(commands[1:]) + arrays = self._evaluator.eval_expression_list(commands[1:]) # *args must be some sort of an array, otherwise -> ignore for array in arrays: @@ -679,12 +679,12 @@ class Execution(Executable): yield None, helpers.FakeStatement(field_stmt) # **kwargs elif commands[0] == '**': - arrays = self._evaluator.follow_call_list(commands[1:]) + arrays = self._evaluator.eval_expression_list(commands[1:]) for array in arrays: if isinstance(array, Array): for key_stmt, value_stmt in array.items(): # first index, is the key if syntactically correct - call = key_stmt.get_commands()[0] + call = key_stmt.expression_list()[0] if isinstance(call, pr.Name): yield call, value_stmt elif isinstance(call, pr.Call): @@ -839,7 +839,7 @@ class Array(use_metaclass(CachedMetaClass, pr.Base, Iterable)): 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_commands()]: + if index_arr and [x for x in index_arr if ':' in x.expression_list()]: # array slicing return [self] @@ -868,7 +868,7 @@ 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.get_commands() + key_commands = key_statement.expression_list() if len(key_commands) != 1: # cannot deal with complex strings continue key = key_commands[0] diff --git a/jedi/helpers.py b/jedi/helpers.py index b80d3a60..c1b8935c 100644 --- a/jedi/helpers.py +++ b/jedi/helpers.py @@ -105,7 +105,7 @@ def array_for_pos(stmt, pos, array_types=None): if stmt.start_pos >= pos >= stmt.end_pos: return None, 0 - for command in stmt.get_commands(): + for command in stmt.expression_list(): arr = None if isinstance(command, pr.Array): arr, index = search_array(command, pos) diff --git a/jedi/modules.py b/jedi/modules.py index 51e0d4fe..686fbb17 100644 --- a/jedi/modules.py +++ b/jedi/modules.py @@ -320,7 +320,7 @@ def sys_path_with_modifications(module): for p in possible_stmts: if not isinstance(p, pr.Statement): continue - commands = p.get_commands() + commands = p.expression_list() # sys.path command is just one thing. if len(commands) != 1 or not isinstance(commands[0], pr.Call): continue diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index ca796187..ab8dfb8b 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -749,7 +749,7 @@ class Statement(Simple): :type start_pos: 2-tuple of int :param start_pos: Position (line, column) of the Statement. """ - __slots__ = ('token_list', '_set_vars', 'as_names', '_commands', + __slots__ = ('token_list', '_set_vars', 'as_names', '_expression_list', '_assignment_details', 'docstr', '_names_are_set_vars') def __init__(self, module, token_list, start_pos, end_pos, parent=None, @@ -771,7 +771,7 @@ class Statement(Simple): self.as_names = list(as_names) # cache - self._commands = None + self._expression_list = None self._assignment_details = [] # this is important for other scripts @@ -788,7 +788,7 @@ class Statement(Simple): return '%s %s ' % (''.join(pieces), assignment) code = ''.join(assemble(*a) for a in self.assignment_details) - code += assemble(self.get_commands()) + code += assemble(self.expression_list()) if self.docstr: code += '\n"""%s"""' % self.docstr @@ -800,12 +800,12 @@ class Statement(Simple): def get_set_vars(self): """ Get the names for the statement. """ if self._set_vars is None: - self._set_vars = [] + def search_calls(calls): for call in calls: if isinstance(call, Array): for stmt in call: - search_calls(stmt.get_commands()) + search_calls(stmt.expression_list()) elif isinstance(call, Call): c = call # Check if there's an execution in it, if so this is @@ -819,12 +819,13 @@ class Statement(Simple): continue self._set_vars.append(call.name) + self._set_vars = [] for calls, operation in self.assignment_details: search_calls(calls) if not self.assignment_details and self._names_are_set_vars: # In the case of Param, it's also a defining name without ``=`` - search_calls(self.get_commands()) + search_calls(self.expression_list()) return self._set_vars + self.as_names def is_global(self): @@ -843,14 +844,14 @@ class Statement(Simple): would result in ``[(Name(x), '='), (Array([Name(y), Name(z)]), '=')]``. """ # parse statement which creates the assignment details. - self.get_commands() + self.expression_list() return self._assignment_details - def get_commands(self): - if self._commands is None: - self._commands = ['time neeeeed'] # avoid recursions - self._commands = self._parse_statement() - return self._commands + def expression_list(self): + if self._expression_list is None: + self._expression_list = ['time neeeeed'] # avoid recursions + self._expression_list = self._parse_statement() + return self._expression_list def _parse_statement(self): """ @@ -1016,7 +1017,7 @@ class Statement(Simple): stmt = Statement(self._sub_module, token_list, start_pos, arr.end_pos) arr.parent = stmt - stmt.token_list = stmt._commands = [arr] + stmt.token_list = stmt._expression_list = [arr] else: for t in stmt.token_list: if isinstance(t, Name): @@ -1126,7 +1127,7 @@ class Statement(Simple): self.parent, set_name_parents=False ) - stmt._commands = result + stmt._expression_list = result arr, break_tok = parse_array(token_iterator, Array.TUPLE, stmt.start_pos, stmt) result = [arr] diff --git a/jedi/refactoring.py b/jedi/refactoring.py index 55494c92..3918420c 100644 --- a/jedi/refactoring.py +++ b/jedi/refactoring.py @@ -176,7 +176,7 @@ 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.get_commands() + commands = 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 diff --git a/test/test_parsing.py b/test/test_parsing.py index 07336afe..b9f2ac55 100644 --- a/test/test_parsing.py +++ b/test/test_parsing.py @@ -17,7 +17,7 @@ def test_user_statement_on_import(): class TestCallAndName(): def get_call(self, source): stmt = Parser(source, no_docstr=True).module.statements[0] - return stmt.get_commands()[0] + return stmt.expression_list()[0] def test_name_and_call_positions(self): call = self.get_call('name\nsomething_else') diff --git a/test/test_regression.py b/test/test_regression.py index 035ca3d8..3152a0ec 100644 --- a/test/test_regression.py +++ b/test/test_regression.py @@ -119,7 +119,7 @@ class TestRegression(TestCase): s = "x()\nx( )\nx( )\nx ( )" parser = Parser(s) for i, s in enumerate(parser.module.statements, 3): - for c in s.get_commands(): + for c in s.expression_list(): self.assertEqual(c.execution.end_pos[1], i) def check_definition_by_marker(self, source, after_cursor, names):