hundreds-breakfast-49010
10/27/2020, 8:35 PMcontextmanager that can accept some kind of output from the context and do something with it after the yield statement?hundreds-father-404
10/27/2020, 8:37 PMflat-zoo-31952
10/27/2020, 8:42 PMfast-nail-55400
10/27/2020, 8:42 PMfast-nail-55400
10/27/2020, 8:44 PM@dataclass
class Context:
foo: Optional[str]
@contextmanager
def some_context_making_func()
obj = Context(None)
yield obj
print(f"output: {obj.foo}")
with some_context_making_func() as obj:
obj.foo = "some output"flat-zoo-31952
10/27/2020, 8:45 PM@contextmanager
def record_calls():
calls = []
yield lambda *args, **kwds: calls.append((args, kwds))
for call in calls:
print(call)
with record_calls() as record:
for i, c in enumerate('abc'):
record(**{c: i})hundreds-breakfast-49010
10/27/2020, 8:46 PM_start_run and _finish_run in local_pants_runner.py into a contexthundreds-breakfast-49010
10/27/2020, 8:46 PM_finish_run needs the engine_result as an argumentflat-zoo-31952
10/27/2020, 8:47 PMBaseException (kinda cheating but the stdlib does it with StopIteration, so who am i to judge)hundreds-breakfast-49010
10/27/2020, 8:48 PMyield that modifies a data structure in the context seems like a reasonably succinct way to do this, thanks for the suggestionflat-zoo-31952
10/27/2020, 8:48 PMhundreds-breakfast-49010
10/27/2020, 8:49 PMflat-zoo-31952
10/27/2020, 8:50 PMflat-zoo-31952
10/27/2020, 8:50 PMhundreds-breakfast-49010
10/27/2020, 8:56 PMwitty-crayon-22786
10/27/2020, 9:03 PMwitty-crayon-22786
10/27/2020, 9:03 PMwitty-crayon-22786
10/27/2020, 9:04 PM