Message194620
IMHO, exitstack is not a very nice construct. It's implementation is far longer than contextlib.nested.
And the chief problem still remains, which has not been addressed until this patch (as far as I know):
In Python, it is impossible to combine existing context managers into a nested one. ExitStack may address a use case of nested context managers, but it doesn't address the basic problem.
ContextManagerExit comes with its own nice little features, too. Now you can write:
@contextlib.contextmanager:
def if_ctxt(condition):
if condition:
yield
#hey look! an if statement as a with statement!
with if_ctxt(condition):
do_work
This can easily be extended, where a context manager can both manage context, _and_ provide optional execution of its block. |
|
Date |
User |
Action |
Args |
2013-08-07 14:59:58 | kristjan.jonsson | set | recipients:
+ kristjan.jonsson, ncoghlan, r.david.murray |
2013-08-07 14:59:58 | kristjan.jonsson | set | messageid: <1375887598.35.0.27585960555.issue18677@psf.upfronthosting.co.za> |
2013-08-07 14:59:58 | kristjan.jonsson | link | issue18677 messages |
2013-08-07 14:59:57 | kristjan.jonsson | create | |
|