forked from VimPlug/jedi
it should be _evaluator not evaluator
This commit is contained in:
@@ -203,6 +203,9 @@ def get_names_of_scope(scope, position=None, star_search=True,
|
|||||||
|
|
||||||
|
|
||||||
class Evaluator(object):
|
class Evaluator(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.cache = None
|
||||||
|
|
||||||
def find_name(self, scope, name_str, position=None, search_global=False,
|
def find_name(self, scope, name_str, position=None, search_global=False,
|
||||||
is_goto=False, resolve_decorator=True):
|
is_goto=False, resolve_decorator=True):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -130,9 +130,9 @@ class ImportPath(pr.Base):
|
|||||||
# ``sys.modules`` modification.
|
# ``sys.modules`` modification.
|
||||||
p = (0, 0)
|
p = (0, 0)
|
||||||
names.append(pr.Name(self.GlobalNamespace, [('path', p)],
|
names.append(pr.Name(self.GlobalNamespace, [('path', p)],
|
||||||
p, p, self.import_stmt))
|
p, p, self.import_stmt))
|
||||||
continue
|
continue
|
||||||
for s, scope_names in evaluate.get_names_of_scope(scope,
|
for s, scope_names in self._evaluator.get_names_of_scope(scope,
|
||||||
include_builtin=False):
|
include_builtin=False):
|
||||||
for n in scope_names:
|
for n in scope_names:
|
||||||
if self.import_stmt.from_ns is None \
|
if self.import_stmt.from_ns is None \
|
||||||
@@ -186,7 +186,7 @@ class ImportPath(pr.Base):
|
|||||||
"""
|
"""
|
||||||
Returns the imported modules.
|
Returns the imported modules.
|
||||||
"""
|
"""
|
||||||
if evaluate.follow_statement.push_stmt(self.import_stmt):
|
if self._evaluator.follow_statement.push_stmt(self.import_stmt):
|
||||||
# check recursion
|
# check recursion
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ class ImportPath(pr.Base):
|
|||||||
scope, rest = self._follow_file_system()
|
scope, rest = self._follow_file_system()
|
||||||
except ModuleNotFound:
|
except ModuleNotFound:
|
||||||
debug.warning('Module not found: ' + str(self.import_stmt))
|
debug.warning('Module not found: ' + str(self.import_stmt))
|
||||||
evaluate.follow_statement.pop_stmt()
|
self._evaluator.follow_statement.pop_stmt()
|
||||||
return []
|
return []
|
||||||
|
|
||||||
scopes = [scope]
|
scopes = [scope]
|
||||||
@@ -210,15 +210,15 @@ class ImportPath(pr.Base):
|
|||||||
# ``os.path``, because it's a very important one in Python
|
# ``os.path``, because it's a very important one in Python
|
||||||
# that is being achieved by messing with ``sys.modules`` in
|
# that is being achieved by messing with ``sys.modules`` in
|
||||||
# ``os``.
|
# ``os``.
|
||||||
scopes = evaluate.follow_path(iter(rest), scope, scope)
|
scopes = self._evaluator.follow_path(iter(rest), scope, scope)
|
||||||
elif rest:
|
elif rest:
|
||||||
if is_goto:
|
if is_goto:
|
||||||
scopes = itertools.chain.from_iterable(
|
scopes = itertools.chain.from_iterable(
|
||||||
evaluate.find_name(s, rest[0], is_goto=True)
|
self._evaluator.find_name(s, rest[0], is_goto=True)
|
||||||
for s in scopes)
|
for s in scopes)
|
||||||
else:
|
else:
|
||||||
scopes = itertools.chain.from_iterable(
|
scopes = itertools.chain.from_iterable(
|
||||||
evaluate.follow_path(iter(rest), s, s)
|
self._evaluator.follow_path(iter(rest), s, s)
|
||||||
for s in scopes)
|
for s in scopes)
|
||||||
scopes = list(scopes)
|
scopes = list(scopes)
|
||||||
|
|
||||||
@@ -228,7 +228,7 @@ class ImportPath(pr.Base):
|
|||||||
scopes = [ImportPath.GlobalNamespace]
|
scopes = [ImportPath.GlobalNamespace]
|
||||||
debug.dbg('after import', scopes)
|
debug.dbg('after import', scopes)
|
||||||
|
|
||||||
evaluate.follow_statement.pop_stmt()
|
self._evaluator.follow_statement.pop_stmt()
|
||||||
return scopes
|
return scopes
|
||||||
|
|
||||||
def _is_relative_import(self):
|
def _is_relative_import(self):
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ class Class(use_metaclass(cache.CachedMetaClass, pr.IsScope)):
|
|||||||
important for descriptors (if the descriptor methods are evaluated or not).
|
important for descriptors (if the descriptor methods are evaluated or not).
|
||||||
"""
|
"""
|
||||||
def __init__(self, evaluator, base):
|
def __init__(self, evaluator, base):
|
||||||
self.evaluator = evaluator
|
self._evaluator = evaluator
|
||||||
self.base = base
|
self.base = base
|
||||||
|
|
||||||
@cache.memoize_default(default=())
|
@cache.memoize_default(default=())
|
||||||
@@ -261,14 +261,14 @@ class Class(use_metaclass(cache.CachedMetaClass, pr.IsScope)):
|
|||||||
# TODO care for mro stuff (multiple super classes).
|
# TODO care for mro stuff (multiple super classes).
|
||||||
for s in self.base.supers:
|
for s in self.base.supers:
|
||||||
# Super classes are statements.
|
# Super classes are statements.
|
||||||
for cls in self.evaluator.follow_statement(s):
|
for cls in self._evaluator.follow_statement(s):
|
||||||
if not isinstance(cls, Class):
|
if not isinstance(cls, Class):
|
||||||
debug.warning('Received non class, as a super class')
|
debug.warning('Received non class, as a super class')
|
||||||
continue # Just ignore other stuff (user input error).
|
continue # Just ignore other stuff (user input error).
|
||||||
supers.append(cls)
|
supers.append(cls)
|
||||||
if not supers and self.base.parent != builtin.Builtin.scope:
|
if not supers and self.base.parent != builtin.Builtin.scope:
|
||||||
# add `object` to classes
|
# add `object` to classes
|
||||||
supers += self.evaluator.find_name(builtin.Builtin.scope, 'object')
|
supers += self._evaluator.find_name(builtin.Builtin.scope, 'object')
|
||||||
return supers
|
return supers
|
||||||
|
|
||||||
@cache.memoize_default(default=())
|
@cache.memoize_default(default=())
|
||||||
@@ -296,7 +296,7 @@ class Class(use_metaclass(cache.CachedMetaClass, pr.IsScope)):
|
|||||||
@cache.memoize_default(default=())
|
@cache.memoize_default(default=())
|
||||||
def get_defined_names(self):
|
def get_defined_names(self):
|
||||||
result = self.instance_names()
|
result = self.instance_names()
|
||||||
type_cls = self.evaluator.find_name(builtin.Builtin.scope, 'type')[0]
|
type_cls = self._evaluator.find_name(builtin.Builtin.scope, 'type')[0]
|
||||||
return result + type_cls.base.get_defined_names()
|
return result + type_cls.base.get_defined_names()
|
||||||
|
|
||||||
def get_subscope_by_name(self, name):
|
def get_subscope_by_name(self, name):
|
||||||
@@ -326,7 +326,7 @@ class Function(use_metaclass(cache.CachedMetaClass, pr.IsScope)):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, evaluator, func, is_decorated=False):
|
def __init__(self, evaluator, func, is_decorated=False):
|
||||||
""" This should not be called directly """
|
""" This should not be called directly """
|
||||||
self.evaluator = evaluator
|
self._evaluator = evaluator
|
||||||
self.base_func = func
|
self.base_func = func
|
||||||
self.is_decorated = is_decorated
|
self.is_decorated = is_decorated
|
||||||
|
|
||||||
@@ -342,7 +342,7 @@ class Function(use_metaclass(cache.CachedMetaClass, pr.IsScope)):
|
|||||||
if not self.is_decorated:
|
if not self.is_decorated:
|
||||||
for dec in reversed(self.base_func.decorators):
|
for dec in reversed(self.base_func.decorators):
|
||||||
debug.dbg('decorator:', dec, f)
|
debug.dbg('decorator:', dec, f)
|
||||||
dec_results = set(self.evaluator.follow_statement(dec))
|
dec_results = set(self._evaluator.follow_statement(dec))
|
||||||
if not len(dec_results):
|
if not len(dec_results):
|
||||||
debug.warning('decorator not found: %s on %s' %
|
debug.warning('decorator not found: %s on %s' %
|
||||||
(dec, self.base_func))
|
(dec, self.base_func))
|
||||||
@@ -415,7 +415,7 @@ class Execution(Executable):
|
|||||||
return []
|
return []
|
||||||
else:
|
else:
|
||||||
if isinstance(stmt, pr.Statement):
|
if isinstance(stmt, pr.Statement):
|
||||||
return self.evaluator.follow_statement(stmt)
|
return self._evaluator.follow_statement(stmt)
|
||||||
else:
|
else:
|
||||||
return [stmt] # just some arbitrary object
|
return [stmt] # just some arbitrary object
|
||||||
|
|
||||||
@@ -455,7 +455,7 @@ class Execution(Executable):
|
|||||||
if len(arr_name.var_args) != 1:
|
if len(arr_name.var_args) != 1:
|
||||||
debug.warning('jedi getattr is too simple')
|
debug.warning('jedi getattr is too simple')
|
||||||
key = arr_name.var_args[0]
|
key = arr_name.var_args[0]
|
||||||
stmts += self.evaluator.follow_path(iter([key]), obj, base)
|
stmts += self._evaluator.follow_path(iter([key]), obj, base)
|
||||||
return stmts
|
return stmts
|
||||||
elif func_name == 'type':
|
elif func_name == 'type':
|
||||||
# otherwise it would be a metaclass
|
# otherwise it would be a metaclass
|
||||||
@@ -511,7 +511,7 @@ class Execution(Executable):
|
|||||||
stmts = docstrings.find_return_types(func)
|
stmts = docstrings.find_return_types(func)
|
||||||
for r in self.returns:
|
for r in self.returns:
|
||||||
if r is not None:
|
if r is not None:
|
||||||
stmts += self.evaluator.follow_statement(r)
|
stmts += self._evaluator.follow_statement(r)
|
||||||
return stmts
|
return stmts
|
||||||
|
|
||||||
@cache.memoize_default(default=())
|
@cache.memoize_default(default=())
|
||||||
@@ -666,7 +666,7 @@ class Execution(Executable):
|
|||||||
if not len(commands):
|
if not len(commands):
|
||||||
continue
|
continue
|
||||||
if commands[0] == '*':
|
if commands[0] == '*':
|
||||||
arrays = self.evaluator.follow_call_list(commands[1:])
|
arrays = self._evaluator.follow_call_list(commands[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,7 +678,7 @@ class Execution(Executable):
|
|||||||
yield None, helpers.FakeStatement(field_stmt)
|
yield None, helpers.FakeStatement(field_stmt)
|
||||||
# **kwargs
|
# **kwargs
|
||||||
elif commands[0] == '**':
|
elif commands[0] == '**':
|
||||||
arrays = self.evaluator.follow_call_list(commands[1:])
|
arrays = self._evaluator.follow_call_list(commands[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():
|
||||||
@@ -831,7 +831,7 @@ class Array(use_metaclass(cache.CachedMetaClass, pr.Base, Iterable)):
|
|||||||
methods which are important in this module.
|
methods which are important in this module.
|
||||||
"""
|
"""
|
||||||
def __init__(self, evaluator, array):
|
def __init__(self, evaluator, array):
|
||||||
self.evaluator = evaluator
|
self._evaluator = evaluator
|
||||||
self._array = array
|
self._array = array
|
||||||
|
|
||||||
def get_index_types(self, index_arr=None):
|
def get_index_types(self, index_arr=None):
|
||||||
@@ -887,7 +887,7 @@ class Array(use_metaclass(cache.CachedMetaClass, pr.Base, Iterable)):
|
|||||||
|
|
||||||
def _follow_values(self, values):
|
def _follow_values(self, values):
|
||||||
""" helper function for the index getters """
|
""" 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.follow_statement(v)
|
||||||
for v in values))
|
for v in values))
|
||||||
|
|
||||||
def get_defined_names(self):
|
def get_defined_names(self):
|
||||||
@@ -896,7 +896,7 @@ class Array(use_metaclass(cache.CachedMetaClass, pr.Base, Iterable)):
|
|||||||
It returns e.g. for a list: append, pop, ...
|
It returns e.g. for a list: append, pop, ...
|
||||||
"""
|
"""
|
||||||
# `array.type` is a string with the type, e.g. 'list'.
|
# `array.type` is a string with the type, e.g. 'list'.
|
||||||
scope = self.evaluator.find_name(builtin.Builtin.scope, self._array.type)[0]
|
scope = self._evaluator.find_name(builtin.Builtin.scope, self._array.type)[0]
|
||||||
scope = Instance(scope)
|
scope = Instance(scope)
|
||||||
names = scope.get_defined_names()
|
names = scope.get_defined_names()
|
||||||
return [ArrayMethod(n) for n in names]
|
return [ArrayMethod(n) for n in names]
|
||||||
|
|||||||
Reference in New Issue
Block a user