Nick Coghlan <ncogh...@gmail.com> added the comment: ContextStack is intended to be a building block that makes it easy to compose context managers and other callbacks, not necessarily an API you'd regularly use directly. For example, given ContextStack (as currently implemented in contextlib2), it's trivial to write your own higher level cleanup API:
@contextmanager def cleanup(cb=None, *args, **kwds): with ContextStack() as stack: if cb is not None: stack.register(cb, *args, **kwds): yield stack If you only have one callback, you could supply it directly as an argument to cleanup(), otherwise you could make multiple register() calls on the returned stack object. The idea is to implement the necessary __exit__() logic that makes it feasible to compose context managers and other callbacks just once, then let people explore the possibilities in terms of the higher level APIs that it makes easy. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue13585> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com