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 Albert.Zeyer, Alexander.Jones, DLitz, Martin Blais, blais, daniel.urban, eric.araujo, georg.brandl, giampaolo.rodola, hniksic, michael.foord, ncoghlan, piotr.dobrogost, pitrou, r.david.murray, rhettinger, vstinner
Date 2017-11-10.01:35:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1510277742.97.0.213398074469.issue10049@psf.upfronthosting.co.za>
In-reply-to
Content
Reopening this based on several years of additional experience with context managers since I wrote https://bugs.python.org/issue10049#msg119514 when originally closing it.

The version I'm now interested in adding is the one from https://bugs.python.org/issue10049#msg281556 - rather than being completely without behaviour, the null context manager should accept the value to be returned from the call to __enter__ as an optional constructor parameter (defaulting to None). That allows even context managers that return a value from __enter__ to be made optional in a relatively obvious way that doesn't involve fundamentally rearranging the code.

I think the overhead argument against the use of ExitStack() for this purpose also has merit (so I'd be curious to see relative performance numbers collected with perf), but it's not my main motive for changing my mind.
History
Date User Action Args
2017-11-10 01:35:43ncoghlansetrecipients: + ncoghlan, georg.brandl, rhettinger, blais, pitrou, vstinner, giampaolo.rodola, hniksic, eric.araujo, r.david.murray, michael.foord, daniel.urban, Albert.Zeyer, piotr.dobrogost, Alexander.Jones, DLitz, Martin Blais
2017-11-10 01:35:42ncoghlansetmessageid: <1510277742.97.0.213398074469.issue10049@psf.upfronthosting.co.za>
2017-11-10 01:35:42ncoghlanlinkissue10049 messages
2017-11-10 01:35:40ncoghlancreate