This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients Julian, eric.araujo, eric.snow, giampaolo.rodola, ncoghlan, nikratio, pitrou, rhettinger, smarnach
Date 2011-12-22.12:01:51
SpamBayes Score 0.0005106305
Marked as misclassified No
Message-id <1324555315.05.0.320576908511.issue13585@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2011-12-22 12:01:55ncoghlansetrecipients: + ncoghlan, rhettinger, pitrou, giampaolo.rodola, eric.araujo, nikratio, Julian, eric.snow, smarnach
2011-12-22 12:01:55ncoghlansetmessageid: <1324555315.05.0.320576908511.issue13585@psf.upfronthosting.co.za>
2011-12-22 12:01:52ncoghlanlinkissue13585 messages
2011-12-22 12:01:51ncoghlancreate