__call__ method is now working

This commit is contained in:
David Halter
2012-05-25 17:00:50 +02:00
parent e7661b1467
commit 5f0926d045
2 changed files with 25 additions and 1 deletions

View File

@@ -93,6 +93,12 @@ class Instance(Executable):
else:
return func
def get_subscope(self, name):
for sub in reversed(self.base.subscopes):
if sub.name.get_code() == name:
return sub
raise KeyError("Couldn't find subscope.")
def get_func_self_name(self, func):
"""
Returns the name of the first param in a class method (which is
@@ -299,7 +305,14 @@ class Execution(Executable):
if hasattr(self.base, 'returns'):
stmts = self._get_function_returns(evaluate_generator)
else:
debug.warning("no execution possible", self.base)
try:
# if it is an instance, we try to execute the __call__().
call_method = self.base.get_subscope('__call__')
except (AttributeError, KeyError):
debug.warning("no execution possible", self.base)
else:
exe = Execution(call_method, self.var_args)
stmts = exe.get_return_types()
debug.dbg('exec results:', stmts, self.base, repr(self))

View File

@@ -126,3 +126,14 @@ SubClass.method_
SubClass.var
#? ['class_sub', 'class_super']
SubClass.class_
# -----------------
# __call__
# -----------------
class CallClass():
def __call__(self):
return 1
#? int()
CallClass()()