mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-18 06:19:39 +08:00
evaluator executions instead of direct instances
This commit is contained in:
@@ -268,9 +268,7 @@ class Evaluator(object):
|
|||||||
c = r.expression_list()[0]
|
c = r.expression_list()[0]
|
||||||
if c in ('*', '**'):
|
if c in ('*', '**'):
|
||||||
t = 'tuple' if c == '*' else 'dict'
|
t = 'tuple' if c == '*' else 'dict'
|
||||||
res_new = [er.Instance(
|
res_new = self.execute(self.find_name(builtin.Builtin.scope, t)[0])
|
||||||
self, self.find_name(builtin.Builtin.scope, t)[0])
|
|
||||||
]
|
|
||||||
if not r.assignment_details:
|
if not r.assignment_details:
|
||||||
# this means that there are no default params,
|
# this means that there are no default params,
|
||||||
# so just ignore it.
|
# so just ignore it.
|
||||||
@@ -346,11 +344,11 @@ class Evaluator(object):
|
|||||||
# not known. Therefore add a new instance for self. Otherwise
|
# not known. Therefore add a new instance for self. Otherwise
|
||||||
# take the existing.
|
# take the existing.
|
||||||
if isinstance(scope, er.InstanceElement):
|
if isinstance(scope, er.InstanceElement):
|
||||||
inst = scope.instance
|
result.append(scope.instance)
|
||||||
else:
|
else:
|
||||||
inst = er.Instance(self, er.Class(self, until()))
|
for inst in self.execute(er.Class(self, until())):
|
||||||
inst.is_generated = True
|
inst.is_generated = True
|
||||||
result.append(inst)
|
result.append(inst)
|
||||||
elif par.isinstance(pr.Statement):
|
elif par.isinstance(pr.Statement):
|
||||||
def is_execution(calls):
|
def is_execution(calls):
|
||||||
for c in calls:
|
for c in calls:
|
||||||
@@ -599,7 +597,9 @@ class Evaluator(object):
|
|||||||
# for pr.Literal
|
# for pr.Literal
|
||||||
scopes = self.find_name(builtin.Builtin.scope, current.type_as_string())
|
scopes = self.find_name(builtin.Builtin.scope, current.type_as_string())
|
||||||
# Make instances of those number/string objects.
|
# Make instances of those number/string objects.
|
||||||
scopes = [er.Instance(self, s, (current.value,)) for s in scopes]
|
scopes = itertools.chain.from_iterable(
|
||||||
|
self.execute(s, (current.value,)) for s in scopes
|
||||||
|
)
|
||||||
types = imports.strip_imports(self, scopes)
|
types = imports.strip_imports(self, scopes)
|
||||||
|
|
||||||
return self.follow_path(path, types, scope, position=position)
|
return self.follow_path(path, types, scope, position=position)
|
||||||
@@ -665,7 +665,7 @@ class Evaluator(object):
|
|||||||
position=position))
|
position=position))
|
||||||
return self.follow_path(path, set(result), scope, position=position)
|
return self.follow_path(path, set(result), scope, position=position)
|
||||||
|
|
||||||
def execute(self, obj, params, evaluate_generator=False):
|
def execute(self, obj, params=(), evaluate_generator=False):
|
||||||
if obj.isinstance(er.Function):
|
if obj.isinstance(er.Function):
|
||||||
obj = obj.get_decorated_func()
|
obj = obj.get_decorated_func()
|
||||||
|
|
||||||
|
|||||||
@@ -487,10 +487,6 @@ def _check_isinstance_type(evaluator, stmt, search_name):
|
|||||||
|
|
||||||
result = []
|
result = []
|
||||||
for c in evaluator.eval_call(classes[0]):
|
for c in evaluator.eval_call(classes[0]):
|
||||||
if isinstance(c, er.Array):
|
for typ in (c.get_index_types() if isinstance(c, er.Array) else [c]):
|
||||||
result += c.get_index_types()
|
result += evaluator.execute(typ)
|
||||||
else:
|
|
||||||
result.append(c)
|
|
||||||
for i, c in enumerate(result):
|
|
||||||
result[i] = er.Instance(evaluator, c)
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ class Instance(use_metaclass(CachedMetaClass, Executable)):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@memoize_default([])
|
@memoize_default([])
|
||||||
def _get_self_attributes(self):
|
def get_self_attributes(self):
|
||||||
def add_self_dot_name(name):
|
def add_self_dot_name(name):
|
||||||
"""
|
"""
|
||||||
Need to copy and rewrite the name, because names are now
|
Need to copy and rewrite the name, because names are now
|
||||||
@@ -117,8 +117,8 @@ class Instance(use_metaclass(CachedMetaClass, Executable)):
|
|||||||
add_self_dot_name(n)
|
add_self_dot_name(n)
|
||||||
|
|
||||||
for s in self.base.get_super_classes():
|
for s in self.base.get_super_classes():
|
||||||
names += Instance(self._evaluator, s)._get_self_attributes()
|
for inst in self._evaluator.execute(s):
|
||||||
|
names += inst.get_self_attributes()
|
||||||
return names
|
return names
|
||||||
|
|
||||||
def get_subscope_by_name(self, name):
|
def get_subscope_by_name(self, name):
|
||||||
@@ -142,7 +142,7 @@ class Instance(use_metaclass(CachedMetaClass, Executable)):
|
|||||||
Get the instance vars of a class. This includes the vars of all
|
Get the instance vars of a class. This includes the vars of all
|
||||||
classes
|
classes
|
||||||
"""
|
"""
|
||||||
names = self._get_self_attributes()
|
names = self.get_self_attributes()
|
||||||
|
|
||||||
class_names = self.base.instance_names()
|
class_names = self.base.instance_names()
|
||||||
for var in class_names:
|
for var in class_names:
|
||||||
@@ -154,7 +154,7 @@ class Instance(use_metaclass(CachedMetaClass, Executable)):
|
|||||||
An Instance has two scopes: The scope with self names and the class
|
An Instance has two scopes: The scope with self names and the class
|
||||||
scope. Instance variables have priority over the class scope.
|
scope. Instance variables have priority over the class scope.
|
||||||
"""
|
"""
|
||||||
yield self, self._get_self_attributes()
|
yield self, self.get_self_attributes()
|
||||||
|
|
||||||
names = []
|
names = []
|
||||||
class_names = self.base.instance_names()
|
class_names = self.base.instance_names()
|
||||||
@@ -719,8 +719,8 @@ class Generator(use_metaclass(CachedMetaClass, pr.Base, Iterable)):
|
|||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
if name not in ['start_pos', 'end_pos', 'parent', 'get_imports',
|
if name not in ['start_pos', 'end_pos', 'parent', 'get_imports',
|
||||||
'asserts', 'doc', 'docstr', 'get_parent_until', 'get_code',
|
'asserts', 'doc', 'docstr', 'get_parent_until',
|
||||||
'subscopes']:
|
'get_code', 'subscopes']:
|
||||||
raise AttributeError("Accessing %s of %s is not allowed."
|
raise AttributeError("Accessing %s of %s is not allowed."
|
||||||
% (self, name))
|
% (self, name))
|
||||||
return getattr(self.func, name)
|
return getattr(self.func, name)
|
||||||
@@ -801,7 +801,7 @@ class Array(use_metaclass(CachedMetaClass, pr.Base, Iterable)):
|
|||||||
"""
|
"""
|
||||||
# `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(self._evaluator, scope)
|
scope = self._evaluator.execute(scope)[0] # builtins only have one class
|
||||||
names = scope.get_defined_names()
|
names = scope.get_defined_names()
|
||||||
return [ArrayMethod(n) for n in names]
|
return [ArrayMethod(n) for n in names]
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ def builtins_super(evaluator, obj, params):
|
|||||||
cls = er.Class(evaluator, cls)
|
cls = er.Class(evaluator, cls)
|
||||||
su = cls.get_super_classes()
|
su = cls.get_super_classes()
|
||||||
if su:
|
if su:
|
||||||
return [er.Instance(evaluator, su[0])]
|
return evaluator.execute(su[0])
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user