properties work now also with initialization values of classes

This commit is contained in:
David Halter
2012-07-10 17:52:46 +02:00
parent e4739fddf9
commit 53358b28d3
5 changed files with 26 additions and 9 deletions

View File

@@ -203,8 +203,9 @@ class Instance(Executable):
def get_descriptor_return(self, obj):
""" Throws an error if there's no method. """
method = self.get_subscope_by_name('__get__')
# args in __set__ descriptors are obj, class.
args = parsing.Array([[obj], [obj.base]], None)
# arguments in __set__ descriptors are obj, class.
# `method` is the new parent of the array, don't know if that's good.
args = parsing.Array('tuple', method, values=[[obj], [obj.base]])
method = InstanceElement(self, method)
res = Execution(method, args).get_return_types()
@@ -390,7 +391,6 @@ class Execution(Executable):
# there maybe executions of executions
stmts = [Instance(self.base, self.var_args)]
elif isinstance(self.base, Generator):
print 'blubedi', self.base
return self.base.execute()
else:
# don't do this with exceptions, as usual, because some deeper
@@ -872,7 +872,6 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
def handle_non_arrays(name):
result = []
par = name.parent
print name, par, par.parent
if isinstance(par, parsing.Flow):
if par.command == 'for':
# take the first statement (for has always only
@@ -1070,7 +1069,7 @@ def follow_call_list(scope, call_list):
result += follow_call_list(scope, call)
else:
# with things like params, these can also be functions, etc
if isinstance(call, (Function, parsing.Class)):
if isinstance(call, (Function, parsing.Class, Instance)):
result.append(call)
# The string tokens are just operations (+, -, etc.)
elif not isinstance(call, str):

View File

@@ -1,4 +1,5 @@
import parsing
import debug
class RecursionDecorator(object):
""" A decorator to detect recursions in statements """
@@ -14,6 +15,7 @@ class RecursionDecorator(object):
r = RecursionNode(stmt, self.current)
if self.check_recursion(r):
debug.warning('catched recursion', stmt, args, kwargs)
return []
parent, self.current = self.current, r
result = self.func(stmt, *args, **kwargs)

View File

@@ -802,10 +802,10 @@ class Array(Call):
DICT = 'dict'
SET = 'set'
def __init__(self, arr_type, parent_stmt, parent=None):
def __init__(self, arr_type, parent_stmt, parent=None, values=None):
super(Array, self).__init__(None, arr_type, parent_stmt, parent)
self.values = []
self.values = values if values else []
self.keys = []
def add_field(self):
@@ -874,7 +874,6 @@ class Array(Call):
type = 'noarray'
else:
type = self.type
#parent_str = " of %s" % self.parent if self.parent else ""
return "<%s: %s%s>" % (self.__class__.__name__, type, self.values)

View File

@@ -66,6 +66,23 @@ nothing("")[0]
#? str()
nothing("")[1]
# -----------------
# properties
# -----------------
class PropClass():
def __init__(self, a):
self.a = a
@property
def ret(self):
return self.a
#? str()
PropClass("").ret
#? []
PropClass().ret.
# -----------------
# not found decorators
# -----------------

View File

@@ -21,5 +21,5 @@ el = scopes.
#? tuple()
el = evaluate.get_names_for_scope()[0]
#? tuple()
##? tuple()
el = evaluate.get_names_for_scope(1,2)[0][0]