From eb30c3e6cfaec2fb89de90c57ee5888a66a9df27 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 27 Dec 2013 11:55:35 +0100 Subject: [PATCH] follow_statement -> eval_statement --- jedi/api.py | 2 +- jedi/api_classes.py | 2 +- jedi/docstrings.py | 4 ++-- jedi/evaluate/__init__.py | 30 ++++++++++++++++-------------- jedi/evaluate/dynamic.py | 10 +++++----- jedi/evaluate/representation.py | 10 +++++----- test/test_integration_import.py | 2 +- 7 files changed, 31 insertions(+), 29 deletions(-) diff --git a/jedi/api.py b/jedi/api.py index a0ff5b9a..dd9ab022 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -242,7 +242,7 @@ class Script(object): else: # just parse one statement, take it and evaluate it stmt = self._get_under_cursor_stmt(goto_path) - scopes = self._evaluator.follow_statement(stmt) + scopes = self._evaluator.eval_statement(stmt) return scopes def _get_under_cursor_stmt(self, cursor_txt): diff --git a/jedi/api_classes.py b/jedi/api_classes.py index 49c41320..2a3ae97e 100644 --- a/jedi/api_classes.py +++ b/jedi/api_classes.py @@ -401,7 +401,7 @@ class Completion(BaseDefinition): """ if self._followed_definitions is None: if self._definition.isinstance(pr.Statement): - defs = self._evaluator.follow_statement(self._definition) + defs = self._evaluator.eval_statement(self._definition) elif self._definition.isinstance(pr.Import): defs = imports.strip_imports(self._evaluator, [self._definition]) else: diff --git a/jedi/docstrings.py b/jedi/docstrings.py index 9f9cefba..31b80097 100644 --- a/jedi/docstrings.py +++ b/jedi/docstrings.py @@ -52,7 +52,7 @@ def follow_param(evaluator, param): p = Parser(param_str, None, user_position, no_docstr=True) if p.user_stmt is None: return [] - return evaluator.follow_statement(p.user_stmt) + return evaluator.eval_statement(p.user_stmt) return [] @@ -127,4 +127,4 @@ def find_return_types(evaluator, func): if p.user_stmt is None: return [] p.user_stmt.parent = func - return list(evaluator.follow_statement(p.user_stmt)) + return list(evaluator.eval_statement(p.user_stmt)) diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index 160306ec..4c227751 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -11,23 +11,23 @@ Evaluation of Python code in |jedi| is based on three assumptions: * The programmer is not a total dick, e.g. like `this `_ :-) -That said, there's mainly one entry point in this script: ``follow_statement``. +That said, there's mainly one entry point in this script: ``eval_statement``. This is where autocompletion starts. Everything you want to complete is either a ``Statement`` or some special name like ``class``, which is easy to complete. -Therefore you need to understand what follows after ``follow_statement``. Let's +Therefore you need to understand what follows after ``eval_statement``. Let's make an example:: import datetime datetime.date.toda# <-- cursor here First of all, this module doesn't care about completion. It really just cares -about ``datetime.date``. At the end of the procedure ``follow_statement`` will +about ``datetime.date``. At the end of the procedure ``eval_statement`` will return the ``datetime`` class. To *visualize* this (simplified): -- ``follow_statement`` - ```` +- ``eval_statement`` - ```` - Unpacking of the statement into ``[[]]`` - ``follow_call_list``, calls ``follow_call`` with ```` @@ -50,7 +50,7 @@ import would contain another Statement like this:: from foo import bar Date = bar.baz -Well... You get it. Just another ``follow_statement`` recursion. It's really +Well... You get it. Just another ``eval_statement`` recursion. It's really easy. Just that Python is not that easy sometimes. To understand tuple assignments and different class scopes, a lot more code had to be written. Yet we're still not talking about Descriptors and Nested List Comprehensions, just @@ -280,7 +280,7 @@ class Evaluator(object): #if r.docstr: #res_new.append(r) - scopes = self.follow_statement(r, seek_name=name_str) + scopes = self.eval_statement(r, seek_name=name_str) add += remove_statements(scopes) if check_instance is not None: @@ -310,7 +310,7 @@ class Evaluator(object): # one, remember `in`). And follow it. if not loop.inputs: return [] - result = get_iterator_types(self.follow_statement(loop.inputs[0])) + result = get_iterator_types(self.eval_statement(loop.inputs[0])) if len(loop.set_vars) > 1: commands = loop.set_stmt.get_commands() # loops with loop.set_vars > 0 only have one command @@ -478,7 +478,7 @@ class Evaluator(object): @memoize_default(default=(), evaluator_is_first_arg=True) @recursion.recursion_decorator - def follow_statement(self, stmt, seek_name=None): + def eval_statement(self, stmt, seek_name=None): """ The starting point of the completion. A statement always owns a call list, which are the calls, that a statement does. @@ -488,9 +488,8 @@ class Evaluator(object): :param stmt: A `pr.Statement`. :param seek_name: A string. """ - debug.dbg('follow_stmt %s (%s)' % (stmt, seek_name)) + debug.dbg('eval_statement %s (%s)' % (stmt, seek_name)) commands = stmt.get_commands() - debug.dbg('calls: %s' % commands) result = self.follow_call_list(commands) @@ -526,11 +525,12 @@ class Evaluator(object): loop = evaluate_list_comprehension(nested_lc, loop) return loop + debug.dbg('follow_call_list: %s' % call_list) result = [] calls_iterator = iter(call_list) for call in calls_iterator: if pr.Array.is_type(call, pr.Array.NOARRAY): - r = list(itertools.chain.from_iterable(self.follow_statement(s) + r = list(itertools.chain.from_iterable(self.eval_statement(s) for s in call)) call_path = call.generate_call_path() next(call_path, None) # the first one has been used already @@ -541,7 +541,7 @@ class Evaluator(object): # Caveat: parents are being changed, but this doesn't matter, # because nothing else uses it. call.stmt.parent = loop - result += self.follow_statement(call.stmt) + result += self.eval_statement(call.stmt) else: if isinstance(call, pr.Lambda): result.append(er.Function(self, call)) @@ -582,7 +582,9 @@ class Evaluator(object): return self.follow_call_path(path, s.parent, s.start_pos) def follow_call_path(self, path, scope, position): - """Follows a path generated by `pr.StatementElement.generate_call_path()`""" + """ + Follows a path generated by `pr.StatementElement.generate_call_path()`. + """ current = next(path) if isinstance(current, pr.Array): @@ -635,7 +637,7 @@ class Evaluator(object): current = next(path) except StopIteration: return None - debug.dbg('follow %s in scope %s' % (current, scope)) + debug.dbg('follow_path: %s in scope %s' % (current, scope)) result = [] if isinstance(current, pr.Array): diff --git a/jedi/evaluate/dynamic.py b/jedi/evaluate/dynamic.py index dc1c43f4..d59f6622 100644 --- a/jedi/evaluate/dynamic.py +++ b/jedi/evaluate/dynamic.py @@ -195,7 +195,7 @@ def search_params(evaluator, param): for params in get_posibilities(evaluator, module, func_name): for p in params: if str(p) == param_name: - result += evaluator.follow_statement(p.parent) + result += evaluator.eval_statement(p.parent) return result func = param.get_parent_until(pr.Function) @@ -317,17 +317,17 @@ def _check_array_additions(evaluator, compare_array, module, is_list): continue # no params: just ignore it if add_name in ['append', 'add']: for param in params: - result += evaluator.follow_statement(param) + result += evaluator.eval_statement(param) elif add_name in ['insert']: try: second_param = params[1] except IndexError: continue else: - result += evaluator.follow_statement(second_param) + result += evaluator.eval_statement(second_param) elif add_name in ['extend', 'update']: for param in params: - iterators = evaluator.follow_statement(param) + iterators = evaluator.eval_statement(param) result += evaluate.get_iterator_types(iterators) return result @@ -411,7 +411,7 @@ class ArrayInstance(pr.Base): items = [] from jedi import evaluate for stmt in self.var_args: - for typ in self._evaluator.follow_statement(stmt): + for typ in self._evaluator.eval_statement(stmt): if isinstance(typ, evaluate.er.Instance) and len(typ.var_args): array = typ.var_args[0] if isinstance(array, ArrayInstance): diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index 432f7395..19077014 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -262,7 +262,7 @@ class Class(use_metaclass(CachedMetaClass, pr.IsScope)): # TODO care for mro stuff (multiple super classes). for s in self.base.supers: # Super classes are statements. - for cls in self._evaluator.follow_statement(s): + for cls in self._evaluator.eval_statement(s): if not isinstance(cls, Class): debug.warning('Received non class, as a super class') continue # Just ignore other stuff (user input error). @@ -343,7 +343,7 @@ class Function(use_metaclass(CachedMetaClass, pr.IsScope)): if not self.is_decorated: for dec in reversed(self.base_func.decorators): debug.dbg('decorator:', dec, f) - dec_results = set(self._evaluator.follow_statement(dec)) + dec_results = set(self._evaluator.eval_statement(dec)) if not len(dec_results): debug.warning('decorator not found: %s on %s' % (dec, self.base_func)) @@ -416,7 +416,7 @@ class Execution(Executable): return [] else: if isinstance(stmt, pr.Statement): - return self._evaluator.follow_statement(stmt) + return self._evaluator.eval_statement(stmt) else: return [stmt] # just some arbitrary object @@ -512,7 +512,7 @@ class Execution(Executable): stmts = docstrings.find_return_types(self._evaluator, func) for r in self.returns: if r is not None: - stmts += self._evaluator.follow_statement(r) + stmts += self._evaluator.eval_statement(r) return stmts @memoize_default(default=()) @@ -889,7 +889,7 @@ class Array(use_metaclass(CachedMetaClass, pr.Base, Iterable)): def _follow_values(self, values): """ helper function for the index getters """ - return list(itertools.chain.from_iterable(self._evaluator.follow_statement(v) + return list(itertools.chain.from_iterable(self._evaluator.eval_statement(v) for v in values)) def get_defined_names(self): diff --git a/test/test_integration_import.py b/test/test_integration_import.py index 4f869f90..92f2ec02 100644 --- a/test/test_integration_import.py +++ b/test/test_integration_import.py @@ -22,7 +22,7 @@ def test_complete_on_empty_import(): assert 10 < len(Script("from . import", 1, 5, '').completions()) < 30 assert 10 < len(Script("from . import classes", 1, 5, '').completions()) < 30 assert len(Script("import").completions()) == 0 - if not is_py26: + if not is_py26: # python 2.6 doesn't always come with a library `import*`. assert len(Script("import import", path='').completions()) > 0 # 111