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 DLitz
Recipients Alexander.Jones, DLitz, daniel.urban, eric.araujo, georg.brandl, giampaolo.rodola, hniksic, michael.foord, ncoghlan, pitrou, r.david.murray, rhettinger, vstinner
Date 2012-11-15.23:23:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1353021827.02.0.729037555595.issue10049@psf.upfronthosting.co.za>
In-reply-to
Content
After seeing a context manager named like "TempfileIfNeeded(..., cond)", whole sole purpose is to handle the conditional case, I'm firmly +1 on this proposal.

It's much easier to just read "with Tempfile() if cond else nullcontext():" than to read through another level of indirection every time someone wanted some conditional logic on a context manager.

Is there any chance that this issue could be reopened?

Perhaps a more elegant solution would be to modify the "with" statement so that any object can be given to it (then we could just use None directly), but I suspect that would be a tad more controversial. ;)
History
Date User Action Args
2012-11-15 23:23:47DLitzsetrecipients: + DLitz, georg.brandl, rhettinger, ncoghlan, pitrou, vstinner, giampaolo.rodola, hniksic, eric.araujo, r.david.murray, michael.foord, daniel.urban, Alexander.Jones
2012-11-15 23:23:47DLitzsetmessageid: <1353021827.02.0.729037555595.issue10049@psf.upfronthosting.co.za>
2012-11-15 23:23:47DLitzlinkissue10049 messages
2012-11-15 23:23:46DLitzcreate