forked from VimPlug/jedi
other modules also adapt to the new evaluate_representation now
This commit is contained in:
+2
-1
@@ -14,6 +14,7 @@ import os
|
|||||||
|
|
||||||
import parsing
|
import parsing
|
||||||
import parsing_representation as pr
|
import parsing_representation as pr
|
||||||
|
import evaluate_representation as er
|
||||||
import dynamic
|
import dynamic
|
||||||
import imports
|
import imports
|
||||||
import evaluate
|
import evaluate
|
||||||
@@ -103,7 +104,7 @@ class Script(object):
|
|||||||
completions = []
|
completions = []
|
||||||
debug.dbg('possible scopes', scopes)
|
debug.dbg('possible scopes', scopes)
|
||||||
for s in scopes:
|
for s in scopes:
|
||||||
if s.isinstance(evaluate.Function):
|
if s.isinstance(er.Function):
|
||||||
names = s.get_magic_method_names()
|
names = s.get_magic_method_names()
|
||||||
else:
|
else:
|
||||||
if isinstance(s, imports.ImportPath):
|
if isinstance(s, imports.ImportPath):
|
||||||
|
|||||||
+10
-9
@@ -16,6 +16,7 @@ import settings
|
|||||||
import evaluate
|
import evaluate
|
||||||
import imports
|
import imports
|
||||||
import parsing_representation as pr
|
import parsing_representation as pr
|
||||||
|
import evaluate_representation as er
|
||||||
import keywords
|
import keywords
|
||||||
|
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ class BaseDefinition(object):
|
|||||||
"""The type of the definition."""
|
"""The type of the definition."""
|
||||||
# generate the type
|
# generate the type
|
||||||
stripped = self.definition
|
stripped = self.definition
|
||||||
if isinstance(self.definition, evaluate.InstanceElement):
|
if isinstance(self.definition, er.InstanceElement):
|
||||||
stripped = self.definition.var
|
stripped = self.definition.var
|
||||||
return type(stripped).__name__
|
return type(stripped).__name__
|
||||||
|
|
||||||
@@ -242,7 +243,7 @@ class Completion(BaseDefinition):
|
|||||||
"""
|
"""
|
||||||
if self._followed_definitions is None:
|
if self._followed_definitions is None:
|
||||||
if self.definition.isinstance(pr.Statement):
|
if self.definition.isinstance(pr.Statement):
|
||||||
defs = evaluate.follow_statement(self.definition)
|
defs = er.follow_statement(self.definition)
|
||||||
elif self.definition.isinstance(pr.Import):
|
elif self.definition.isinstance(pr.Import):
|
||||||
defs = imports.strip_imports([self.definition])
|
defs = imports.strip_imports([self.definition])
|
||||||
else:
|
else:
|
||||||
@@ -273,18 +274,18 @@ class Definition(BaseDefinition):
|
|||||||
in testing. e.g. for ``isinstance`` it returns ``def isinstance``.
|
in testing. e.g. for ``isinstance`` it returns ``def isinstance``.
|
||||||
"""
|
"""
|
||||||
d = self.definition
|
d = self.definition
|
||||||
if isinstance(d, evaluate.InstanceElement):
|
if isinstance(d, er.InstanceElement):
|
||||||
d = d.var
|
d = d.var
|
||||||
if isinstance(d, pr.Name):
|
if isinstance(d, pr.Name):
|
||||||
d = d.parent
|
d = d.parent
|
||||||
|
|
||||||
if isinstance(d, evaluate.Array):
|
if isinstance(d, er.Array):
|
||||||
d = 'class ' + d.type
|
d = 'class ' + d.type
|
||||||
elif isinstance(d, (pr.Class, evaluate.Class, evaluate.Instance)):
|
elif isinstance(d, (pr.Class, er.Class, er.Instance)):
|
||||||
d = 'class ' + unicode(d.name)
|
d = 'class ' + unicode(d.name)
|
||||||
elif isinstance(d, (evaluate.Function, pr.Function)):
|
elif isinstance(d, (er.Function, pr.Function)):
|
||||||
d = 'def ' + unicode(d.name)
|
d = 'def ' + unicode(d.name)
|
||||||
elif isinstance(d, evaluate.pr.Module):
|
elif isinstance(d, pr.Module):
|
||||||
# only show module name
|
# only show module name
|
||||||
d = 'module %s' % self.module_name
|
d = 'module %s' % self.module_name
|
||||||
elif self.is_keyword:
|
elif self.is_keyword:
|
||||||
@@ -344,8 +345,8 @@ class CallDef(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def params(self):
|
def params(self):
|
||||||
if self.executable.isinstance(evaluate.Function):
|
if self.executable.isinstance(er.Function):
|
||||||
if isinstance(self.executable, evaluate.InstanceElement):
|
if isinstance(self.executable, er.InstanceElement):
|
||||||
return self.executable.params[1:]
|
return self.executable.params[1:]
|
||||||
return self.executable.params
|
return self.executable.params
|
||||||
else:
|
else:
|
||||||
|
|||||||
+4
-4
@@ -3,8 +3,8 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
import evaluate
|
import evaluate
|
||||||
|
import evaluate_representation as er
|
||||||
import parsing
|
import parsing
|
||||||
import parsing_representation as pr
|
|
||||||
|
|
||||||
DOCSTRING_PARAM_PATTERNS = [
|
DOCSTRING_PARAM_PATTERNS = [
|
||||||
r'\s*:type\s+%s:\s*([^\n]+)', # Sphinx
|
r'\s*:type\s+%s:\s*([^\n]+)', # Sphinx
|
||||||
@@ -89,10 +89,10 @@ def strip_rest_role(type_str):
|
|||||||
|
|
||||||
|
|
||||||
def find_return_types(func):
|
def find_return_types(func):
|
||||||
if isinstance(func, evaluate.InstanceElement):
|
if isinstance(func, er.InstanceElement):
|
||||||
func = func.var
|
func = func.var
|
||||||
|
|
||||||
if isinstance(func, evaluate.Function):
|
if isinstance(func, er.Function):
|
||||||
func = func.base_func
|
func = func.base_func
|
||||||
|
|
||||||
type_str = search_return_in_docstr(func.docstr)
|
type_str = search_return_in_docstr(func.docstr)
|
||||||
@@ -101,7 +101,7 @@ def find_return_types(func):
|
|||||||
|
|
||||||
p = parsing.Parser(type_str, None, (1, 0), no_docstr=True)
|
p = parsing.Parser(type_str, None, (1, 0), no_docstr=True)
|
||||||
p.user_stmt.parent = func
|
p.user_stmt.parent = func
|
||||||
return list(evaluate.follow_statement(p.user_stmt))
|
return list(er.follow_statement(p.user_stmt))
|
||||||
|
|
||||||
def search_return_in_docstr(code):
|
def search_return_in_docstr(code):
|
||||||
for p in DOCSTRING_RETURN_PATTERNS:
|
for p in DOCSTRING_RETURN_PATTERNS:
|
||||||
|
|||||||
+11
-10
@@ -11,6 +11,7 @@ import os
|
|||||||
|
|
||||||
import cache
|
import cache
|
||||||
import parsing_representation as pr
|
import parsing_representation as pr
|
||||||
|
import evaluate_representation as er
|
||||||
import modules
|
import modules
|
||||||
import evaluate
|
import evaluate
|
||||||
import helpers
|
import helpers
|
||||||
@@ -255,13 +256,13 @@ def _check_array_additions(compare_array, module, is_list):
|
|||||||
|
|
||||||
def get_execution_parent(element, *stop_classes):
|
def get_execution_parent(element, *stop_classes):
|
||||||
""" Used to get an Instance/Execution parent """
|
""" Used to get an Instance/Execution parent """
|
||||||
if isinstance(element, evaluate.Array):
|
if isinstance(element, er.Array):
|
||||||
stmt = element._array.parent_stmt
|
stmt = element._array.parent_stmt
|
||||||
else:
|
else:
|
||||||
# must be instance
|
# must be instance
|
||||||
stmt = element.var_args.parent_stmt
|
stmt = element.var_args.parent_stmt
|
||||||
if isinstance(stmt, evaluate.InstanceElement):
|
if isinstance(stmt, er.InstanceElement):
|
||||||
stop_classes = list(stop_classes) + [evaluate.Function]
|
stop_classes = list(stop_classes) + [er.Function]
|
||||||
return stmt.get_parent_until(stop_classes)
|
return stmt.get_parent_until(stop_classes)
|
||||||
|
|
||||||
temp_param_add = settings.dynamic_params_for_other_modules
|
temp_param_add = settings.dynamic_params_for_other_modules
|
||||||
@@ -269,7 +270,7 @@ def _check_array_additions(compare_array, module, is_list):
|
|||||||
|
|
||||||
search_names = ['append', 'extend', 'insert'] if is_list else \
|
search_names = ['append', 'extend', 'insert'] if is_list else \
|
||||||
['add', 'update']
|
['add', 'update']
|
||||||
comp_arr_parent = get_execution_parent(compare_array, evaluate.Execution)
|
comp_arr_parent = get_execution_parent(compare_array, er.Execution)
|
||||||
possible_stmts = []
|
possible_stmts = []
|
||||||
res = []
|
res = []
|
||||||
for n in search_names:
|
for n in search_names:
|
||||||
@@ -282,15 +283,15 @@ def _check_array_additions(compare_array, module, is_list):
|
|||||||
# can search for the same statement, that is in the module
|
# can search for the same statement, that is in the module
|
||||||
# dict. Executions are somewhat special in jedi, since they
|
# dict. Executions are somewhat special in jedi, since they
|
||||||
# literally copy the contents of a function.
|
# literally copy the contents of a function.
|
||||||
if isinstance(comp_arr_parent, evaluate.Execution):
|
if isinstance(comp_arr_parent, er.Execution):
|
||||||
stmt = comp_arr_parent. \
|
stmt = comp_arr_parent. \
|
||||||
get_statement_for_position(stmt.start_pos)
|
get_statement_for_position(stmt.start_pos)
|
||||||
if stmt is None:
|
if stmt is None:
|
||||||
continue
|
continue
|
||||||
# InstanceElements are special, because they don't get copied,
|
# InstanceElements are special, because they don't get copied,
|
||||||
# but have this wrapper around them.
|
# but have this wrapper around them.
|
||||||
if isinstance(comp_arr_parent, evaluate.InstanceElement):
|
if isinstance(comp_arr_parent, er.InstanceElement):
|
||||||
stmt = evaluate.InstanceElement(comp_arr_parent.instance, stmt)
|
stmt = er.InstanceElement(comp_arr_parent.instance, stmt)
|
||||||
|
|
||||||
if evaluate.follow_statement.push_stmt(stmt):
|
if evaluate.follow_statement.push_stmt(stmt):
|
||||||
# check recursion
|
# check recursion
|
||||||
@@ -327,7 +328,7 @@ class ArrayInstance(pr.Base):
|
|||||||
"""
|
"""
|
||||||
items = []
|
items = []
|
||||||
for array in evaluate.follow_call_list(self.var_args):
|
for array in evaluate.follow_call_list(self.var_args):
|
||||||
if isinstance(array, evaluate.Instance) and len(array.var_args):
|
if isinstance(array, er.Instance) and len(array.var_args):
|
||||||
temp = array.var_args[0][0]
|
temp = array.var_args[0][0]
|
||||||
if isinstance(temp, ArrayInstance):
|
if isinstance(temp, ArrayInstance):
|
||||||
# prevent recursions
|
# prevent recursions
|
||||||
@@ -474,12 +475,12 @@ def check_statement_information(stmt, search_name):
|
|||||||
assert isinstance(classes_call, pr.Call)
|
assert isinstance(classes_call, pr.Call)
|
||||||
result = []
|
result = []
|
||||||
for c in evaluate.follow_call(classes_call):
|
for c in evaluate.follow_call(classes_call):
|
||||||
if isinstance(c, evaluate.Array):
|
if isinstance(c, er.Array):
|
||||||
result += c.get_index_types()
|
result += c.get_index_types()
|
||||||
else:
|
else:
|
||||||
result.append(c)
|
result.append(c)
|
||||||
for i, c in enumerate(result):
|
for i, c in enumerate(result):
|
||||||
result[i] = evaluate.Instance(c)
|
result[i] = er.Instance(c)
|
||||||
return result
|
return result
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
return []
|
return []
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
import copy
|
import copy
|
||||||
|
|
||||||
import parsing_representation as pr
|
import parsing_representation as pr
|
||||||
import evaluate
|
import evaluate_representation as er
|
||||||
import debug
|
import debug
|
||||||
import builtin
|
import builtin
|
||||||
import settings
|
import settings
|
||||||
@@ -119,7 +119,7 @@ class ExecutionRecursionDecorator(object):
|
|||||||
if cls.execution_count > settings.max_executions:
|
if cls.execution_count > settings.max_executions:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if isinstance(execution.base, (evaluate.Generator, evaluate.Array)):
|
if isinstance(execution.base, (er.Generator, er.Array)):
|
||||||
return False
|
return False
|
||||||
module = execution.get_parent_until()
|
module = execution.get_parent_until()
|
||||||
if evaluate_generator or module == builtin.Builtin.scope:
|
if evaluate_generator or module == builtin.Builtin.scope:
|
||||||
|
|||||||
Reference in New Issue
Block a user