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 <rep...@bugs.python.org>
Python-bugs-list mailing list

Reply via email to