[issue10049] Add a "no-op" (null) context manager to contextlib

Nick Coghlan report at bugs.python.org
Thu Nov 9 20:35:42 EST 2017


Nick Coghlan <ncoghlan at gmail.com> added the comment:

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.

----------
resolution: rejected -> 
status: closed -> open
title: Add a "no-op" (null) context manager to contextlib (Rejected: use contextlib.ExitStack()) -> Add a "no-op" (null) context manager to contextlib

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue10049>
_______________________________________


More information about the Python-bugs-list mailing list