mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-30 21:05:21 +08:00
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):
|
||||
def __init__(self):
|
||||
self.cache = None
|
||||
|
||||
def find_name(self, scope, name_str, position=None, search_global=False,
|
||||
is_goto=False, resolve_decorator=True):
|
||||
"""
|
||||
|
||||
@@ -130,9 +130,9 @@ class ImportPath(pr.Base):
|
||||
# ``sys.modules`` modification.
|
||||
p = (0, 0)
|
||||
names.append(pr.Name(self.GlobalNamespace, [('path', p)],
|
||||
p, p, self.import_stmt))
|
||||
p, p, self.import_stmt))
|
||||
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):
|
||||
for n in scope_names:
|
||||
if self.import_stmt.from_ns is None \
|
||||
@@ -186,7 +186,7 @@ class ImportPath(pr.Base):
|
||||
"""
|
||||
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
|
||||
return []
|
||||
|
||||
@@ -195,7 +195,7 @@ class ImportPath(pr.Base):
|
||||
scope, rest = self._follow_file_system()
|
||||
except ModuleNotFound:
|
||||
debug.warning('Module not found: ' + str(self.import_stmt))
|
||||
evaluate.follow_statement.pop_stmt()
|
||||
self._evaluator.follow_statement.pop_stmt()
|
||||
return []
|
||||
|
||||
scopes = [scope]
|
||||
@@ -210,15 +210,15 @@ class ImportPath(pr.Base):
|
||||
# ``os.path``, because it's a very important one in Python
|
||||
# that is being achieved by messing with ``sys.modules`` in
|
||||
# ``os``.
|
||||
scopes = evaluate.follow_path(iter(rest), scope, scope)
|
||||
scopes = self._evaluator.follow_path(iter(rest), scope, scope)
|
||||
elif rest:
|
||||
if is_goto:
|
||||
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)
|
||||
else:
|
||||
scopes = itertools.chain.from_iterable(
|
||||
evaluate.follow_path(iter(rest), s, s)
|
||||
self._evaluator.follow_path(iter(rest), s, s)
|
||||
for s in scopes)
|
||||
scopes = list(scopes)
|
||||
|
||||
@@ -228,7 +228,7 @@ class ImportPath(pr.Base):
|
||||
scopes = [ImportPath.GlobalNamespace]
|
||||
debug.dbg('after import', scopes)
|
||||
|
||||
evaluate.follow_statement.pop_stmt()
|
||||
self._evaluator.follow_statement.pop_stmt()
|
||||
return scopes
|
||||
|
||||
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).
|
||||
"""
|
||||
def __init__(self, evaluator, base):
|
||||
self.evaluator = evaluator
|
||||
self._evaluator = evaluator
|
||||
self.base = base
|
||||
|
||||
@cache.memoize_default(default=())
|
||||
@@ -261,14 +261,14 @@ class Class(use_metaclass(cache.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.follow_statement(s):
|
||||
if not isinstance(cls, Class):
|
||||
debug.warning('Received non class, as a super class')
|
||||
continue # Just ignore other stuff (user input error).
|
||||
supers.append(cls)
|
||||
if not supers and self.base.parent != builtin.Builtin.scope:
|
||||
# add `object` to classes
|
||||
supers += self.evaluator.find_name(builtin.Builtin.scope, 'object')
|
||||
supers += self._evaluator.find_name(builtin.Builtin.scope, 'object')
|
||||
return supers
|
||||
|
||||
@cache.memoize_default(default=())
|
||||
@@ -296,7 +296,7 @@ class Class(use_metaclass(cache.CachedMetaClass, pr.IsScope)):
|
||||
@cache.memoize_default(default=())
|
||||
def get_defined_names(self):
|
||||
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()
|
||||
|
||||
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):
|
||||
""" This should not be called directly """
|
||||
self.evaluator = evaluator
|
||||
self._evaluator = evaluator
|
||||
self.base_func = func
|
||||
self.is_decorated = is_decorated
|
||||
|
||||
@@ -342,7 +342,7 @@ class Function(use_metaclass(cache.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.follow_statement(dec))
|
||||
if not len(dec_results):
|
||||
debug.warning('decorator not found: %s on %s' %
|
||||
(dec, self.base_func))
|
||||
@@ -415,7 +415,7 @@ class Execution(Executable):
|
||||
return []
|
||||
else:
|
||||
if isinstance(stmt, pr.Statement):
|
||||
return self.evaluator.follow_statement(stmt)
|
||||
return self._evaluator.follow_statement(stmt)
|
||||
else:
|
||||
return [stmt] # just some arbitrary object
|
||||
|
||||
@@ -455,7 +455,7 @@ class Execution(Executable):
|
||||
if len(arr_name.var_args) != 1:
|
||||
debug.warning('jedi getattr is too simple')
|
||||
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
|
||||
elif func_name == 'type':
|
||||
# otherwise it would be a metaclass
|
||||
@@ -511,7 +511,7 @@ class Execution(Executable):
|
||||
stmts = docstrings.find_return_types(func)
|
||||
for r in self.returns:
|
||||
if r is not None:
|
||||
stmts += self.evaluator.follow_statement(r)
|
||||
stmts += self._evaluator.follow_statement(r)
|
||||
return stmts
|
||||
|
||||
@cache.memoize_default(default=())
|
||||
@@ -666,7 +666,7 @@ class Execution(Executable):
|
||||
if not len(commands):
|
||||
continue
|
||||
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
|
||||
|
||||
for array in arrays:
|
||||
@@ -678,7 +678,7 @@ class Execution(Executable):
|
||||
yield None, helpers.FakeStatement(field_stmt)
|
||||
# **kwargs
|
||||
elif commands[0] == '**':
|
||||
arrays = self.evaluator.follow_call_list(commands[1:])
|
||||
arrays = self._evaluator.follow_call_list(commands[1:])
|
||||
for array in arrays:
|
||||
if isinstance(array, Array):
|
||||
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.
|
||||
"""
|
||||
def __init__(self, evaluator, array):
|
||||
self.evaluator = evaluator
|
||||
self._evaluator = evaluator
|
||||
self._array = array
|
||||
|
||||
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):
|
||||
""" 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))
|
||||
|
||||
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, ...
|
||||
"""
|
||||
# `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)
|
||||
names = scope.get_defined_names()
|
||||
return [ArrayMethod(n) for n in names]
|
||||
|
||||
Reference in New Issue
Block a user