evaluator executions instead of direct instances

This commit is contained in:
Dave Halter
2013-12-29 19:40:45 +01:00
parent 0f6b5b222b
commit 8561217333
4 changed files with 20 additions and 24 deletions

View File

@@ -268,9 +268,7 @@ class Evaluator(object):
c = r.expression_list()[0]
if c in ('*', '**'):
t = 'tuple' if c == '*' else 'dict'
res_new = [er.Instance(
self, self.find_name(builtin.Builtin.scope, t)[0])
]
res_new = self.execute(self.find_name(builtin.Builtin.scope, t)[0])
if not r.assignment_details:
# this means that there are no default params,
# so just ignore it.
@@ -346,11 +344,11 @@ class Evaluator(object):
# not known. Therefore add a new instance for self. Otherwise
# take the existing.
if isinstance(scope, er.InstanceElement):
inst = scope.instance
result.append(scope.instance)
else:
inst = er.Instance(self, er.Class(self, until()))
inst.is_generated = True
result.append(inst)
for inst in self.execute(er.Class(self, until())):
inst.is_generated = True
result.append(inst)
elif par.isinstance(pr.Statement):
def is_execution(calls):
for c in calls:
@@ -599,7 +597,9 @@ class Evaluator(object):
# for pr.Literal
scopes = self.find_name(builtin.Builtin.scope, current.type_as_string())
# 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)
return self.follow_path(path, types, scope, position=position)
@@ -665,7 +665,7 @@ class Evaluator(object):
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):
obj = obj.get_decorated_func()

View File

@@ -487,10 +487,6 @@ def _check_isinstance_type(evaluator, stmt, search_name):
result = []
for c in evaluator.eval_call(classes[0]):
if isinstance(c, er.Array):
result += c.get_index_types()
else:
result.append(c)
for i, c in enumerate(result):
result[i] = er.Instance(evaluator, c)
for typ in (c.get_index_types() if isinstance(c, er.Array) else [c]):
result += evaluator.execute(typ)
return result

View File

@@ -80,7 +80,7 @@ class Instance(use_metaclass(CachedMetaClass, Executable)):
return None
@memoize_default([])
def _get_self_attributes(self):
def get_self_attributes(self):
def add_self_dot_name(name):
"""
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)
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
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
classes
"""
names = self._get_self_attributes()
names = self.get_self_attributes()
class_names = self.base.instance_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
scope. Instance variables have priority over the class scope.
"""
yield self, self._get_self_attributes()
yield self, self.get_self_attributes()
names = []
class_names = self.base.instance_names()
@@ -719,8 +719,8 @@ class Generator(use_metaclass(CachedMetaClass, pr.Base, Iterable)):
def __getattr__(self, name):
if name not in ['start_pos', 'end_pos', 'parent', 'get_imports',
'asserts', 'doc', 'docstr', 'get_parent_until', 'get_code',
'subscopes']:
'asserts', 'doc', 'docstr', 'get_parent_until',
'get_code', 'subscopes']:
raise AttributeError("Accessing %s of %s is not allowed."
% (self, 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'.
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()
return [ArrayMethod(n) for n in names]

View File

@@ -77,7 +77,7 @@ def builtins_super(evaluator, obj, params):
cls = er.Class(evaluator, cls)
su = cls.get_super_classes()
if su:
return [er.Instance(evaluator, su[0])]
return evaluator.execute(su[0])
return []