descriptors are now also working with classes. this means classmethod/staticmethod are now working

This commit is contained in:
David Halter
2012-07-19 18:29:04 +02:00
parent b432090f58
commit 4cd1efc5ba
3 changed files with 22 additions and 15 deletions

View File

@@ -558,8 +558,11 @@ class Execution(Executable):
def iterate(): def iterate():
# `var_args` is typically an Array, and not a list. # `var_args` is typically an Array, and not a list.
for var_arg in self.var_args: for var_arg in self.var_args:
# empty var_arg
if len(var_arg) == 0:
yield None, None
# *args # *args
if var_arg[0] == '*': elif var_arg[0] == '*':
arrays = follow_call_list([var_arg[1:]]) arrays = follow_call_list([var_arg[1:]])
for array in arrays: for array in arrays:
for field in array.get_contents(): for field in array.get_contents():
@@ -958,7 +961,7 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
res_new = [] res_new = []
#print 'descc', scope, result, name_str #print 'descc', scope, result, name_str
for r in result: for r in result:
if isinstance(scope, (Instance)) \ if isinstance(scope, (Instance, Class)) \
and hasattr(r, 'get_descriptor_return'): and hasattr(r, 'get_descriptor_return'):
# handle descriptors # handle descriptors
try: try:
@@ -1079,7 +1082,7 @@ def follow_call_list(call_list):
result += follow_call_list(call) result += follow_call_list(call)
else: else:
# With things like params, these can also be functions... # With things like params, these can also be functions...
if isinstance(call, (Function, parsing.Class, Instance)): if isinstance(call, (Function, Class, Instance)):
result.append(call) result.append(call)
# The string tokens are just operations (+, -, etc.) # The string tokens are just operations (+, -, etc.)
elif not isinstance(call, str): elif not isinstance(call, str):

View File

@@ -47,5 +47,5 @@ class classmethod():
def __get__(self, obj, cls): def __get__(self, obj, cls):
def _method(*args, **kwargs): def _method(*args, **kwargs):
self._func(cls, *args, **kwargs) return self._func(cls, *args, **kwargs)
return _method return _method

View File

@@ -236,6 +236,10 @@ class RevealAccess(object):
class C(object): class C(object):
x = RevealAccess(10, 'var "x"') x = RevealAccess(10, 'var "x"')
#? RevealAccess()
x
#? ['__get__']
x.__get__
y = 5.0 y = 5.0
m = C() m = C()
@@ -243,7 +247,7 @@ m = C()
m.x m.x
#? float() #? float()
m.y m.y
##? int() #? int()
C.x C.x
# ----------------- # -----------------
@@ -335,25 +339,25 @@ class E(object):
return cls.a return cls.a
e = E(1) e = E(1)
##? int() #? int()
e.f(1) e.f(1)
##? int() #? int()
E.f(1) E.f(1)
##? int() #? int()
e.g(1) e.g(1)
##? int() #? int()
E.g(1) E.g(1)
##? int() #? int()
e.s(1) e.s(1)
##? int() #? int()
E.s(1) E.s(1)
##? int() #? int()
e.t(1) e.t(1)
##? int() #? int()
E.t(1) E.t(1)
##? str() #? str()
e.u(1) e.u(1)
##? str() #? str()
E.u(1) E.u(1)