From 3560e974c4f4773eec6cd295be6252cd89010880 Mon Sep 17 00:00:00 2001 From: Romain Dorgueil Date: Sat, 13 May 2017 15:24:31 +0200 Subject: [PATCH] Allow processors to retrieve their own value from the yield value, making it one line shorter each time the processor does not need its value before the teardown phase. --- bonobo/config/processors.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bonobo/config/processors.py b/bonobo/config/processors.py index 2d3de8f..f7bd601 100644 --- a/bonobo/config/processors.py +++ b/bonobo/config/processors.py @@ -49,6 +49,7 @@ class ContextCurrifier: self.wrapped = wrapped self.context = tuple(initial_context) self._stack = [] + self._stack_values = [] def setup(self, *context): if len(self._stack): @@ -56,6 +57,7 @@ class ContextCurrifier: for processor in resolve_processors(self.wrapped): _processed = processor(self.wrapped, *context, *self.context) _append_to_context = next(_processed) + self._stack_values.append(_append_to_context) if _append_to_context is not None: self.context += ensure_tuple(_append_to_context) self._stack.append(_processed) @@ -68,7 +70,7 @@ class ContextCurrifier: processor = self._stack.pop() try: # todo yield from ? how to ? - next(processor) + processor.send(self._stack_values.pop()) except StopIteration as exc: # This is normal, and wanted. pass