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

Dwayne Litzenberger report at bugs.python.org
Fri Nov 16 00:23:47 CET 2012


Dwayne Litzenberger added the comment:

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. ;)

----------
nosy: +DLitz

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


More information about the Python-bugs-list mailing list