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 Julian
Recipients Julian, eric.snow, giampaolo.rodola, nikratio, rhettinger, smarnach
Date 2011-12-13.00:23:25
SpamBayes Score 6.54845e-06
Marked as misclassified No
Message-id <>
For reference, the implementation that I posted in the other thread is:

    def maybe(got, contextfactory, *args, checkif=bool, **kwargs):
        if checkif(got):
            yield got
            with contextfactory(*args, **kwargs) as got:
                yield got

which produces code like:

def fn(input_file=None):
    with maybe(input_file, open, "/default/input/file/location/"):
        for line in input_file:
            print line

For the example given here in the OP, since rmtree isn't a contextmanager it'd require wrapping it in one first.

I could probably understand if there was desire for these to be a recipe instead. The advantage (if any) of the above over this class is that it keeps context managers sorta looking like context managers. Here if you wanted to write my example it'd require writing code like

with ContextManager() as mgr:
    foo = ctxtmgr()

which doesn't look too great :/

The class though does have wider scope though, since it doesn't necessarily only need a context manager, it can do cleanup for anything, which I guess is nice.
Date User Action Args
2011-12-13 00:23:26Juliansetrecipients: + Julian, rhettinger, giampaolo.rodola, nikratio, eric.snow, smarnach
2011-12-13 00:23:26Juliansetmessageid: <>
2011-12-13 00:23:25Julianlinkissue13585 messages
2011-12-13 00:23:25Juliancreate