diff --git a/py/_com.py b/py/_com.py index a93cd876f..de0d79bd3 100644 --- a/py/_com.py +++ b/py/_com.py @@ -52,6 +52,9 @@ class MultiCall: res = self.currentmethod(self, *self.args, **self.kwargs) else: res = self.currentmethod(*self.args, **self.kwargs) + if hasattr(self, '_ex1'): + self.results = [res] + break if res is not None: if res is self.NONEASRESULT: res = None @@ -63,6 +66,9 @@ class MultiCall: if self.results: return self.results[-1] + def exclude_other_results(self): + self._ex1 = True + class PyPlugins: """ Manage Plugins: Load plugins and manage calls to plugins. diff --git a/py/misc/testing/test_com.py b/py/misc/testing/test_com.py index 84fa0b412..6122ab124 100644 --- a/py/misc/testing/test_com.py +++ b/py/misc/testing/test_com.py @@ -49,6 +49,22 @@ class TestMultiCall: call = MultiCall([n, m]) res = call.execute(firstresult=True) assert res == 2 + + def test_call_exclude_other_results(self): + def m(__call__): + __call__.exclude_other_results() + return 10 + + def n(): + return 1 + + call = MultiCall([n, n, m, n]) + res = call.execute() + assert res == [10] + # doesn't really make sense for firstresult-mode - because + # we might not have had a chance to run at all. + #res = call.execute(firstresult=True) + #assert res == 10 class TestPyPlugins: