diff --git a/evaluate.py b/evaluate.py index c966c33f..a8567ed9 100644 --- a/evaluate.py +++ b/evaluate.py @@ -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)) diff --git a/test/completion/classes.py b/test/completion/classes.py index eb3f5abf..6b34a849 100644 --- a/test/completion/classes.py +++ b/test/completion/classes.py @@ -126,3 +126,14 @@ SubClass.method_ SubClass.var #? ['class_sub', 'class_super'] SubClass.class_ + +# ----------------- +# __call__ +# ----------------- + +class CallClass(): + def __call__(self): + return 1 + +#? int() +CallClass()()