Nick Coghlan <ncogh...@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 <rep...@bugs.python.org> <https://bugs.python.org/issue10049> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com