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 giampaolo.rodola
Recipients Alexander.Jones, DLitz, Martin Blais, daniel.urban, eric.araujo, georg.brandl, giampaolo.rodola, hniksic, michael.foord, ncoghlan, piotr.dobrogost, pitrou, r.david.murray, rhettinger, vstinner
Date 2016-11-18.23:30:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1479511819.3.0.40199801098.issue10049@psf.upfronthosting.co.za>
In-reply-to
Content
ExitStack() already covers the "null ctx mgr" use case described in the first message. Original example:


with transaction or contextlib.null():
    ...


By using ExitStack:


with transaction or ExitStack():
    ...


You can push this further and do this, which is even more flexible:


with ExitStack() as stack:
    if condition:
        stack.enter_context(transaction)
    ...


So ExitStack really is better than the original proposal which could have made sense 6 years ago but not anymore.
History
Date User Action Args
2016-11-18 23:30:19giampaolo.rodolasetrecipients: + giampaolo.rodola, georg.brandl, rhettinger, ncoghlan, pitrou, vstinner, hniksic, eric.araujo, r.david.murray, michael.foord, daniel.urban, piotr.dobrogost, Alexander.Jones, DLitz, Martin Blais
2016-11-18 23:30:19giampaolo.rodolasetmessageid: <1479511819.3.0.40199801098.issue10049@psf.upfronthosting.co.za>
2016-11-18 23:30:19giampaolo.rodolalinkissue10049 messages
2016-11-18 23:30:19giampaolo.rodolacreate