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

Hrvoje Nikšić report at bugs.python.org
Fri Oct 8 14:04:39 CEST 2010


Hrvoje Nikšić <hniksic at gmail.com> added the comment:

That is what we are using now, but I think a contextlib.null() would be useful to others, i.e. that its use is a useful idiom to adopt.  Specifically I would like to discourage the "duplicated code" idiom from the report, which I've seen all too often.

The "closing" constructor is also trivial to define, but it's there for convenience and to promote the use of with statement over try/finally boilerplate.  The same goes here: you don't miss the null context manager when you don't have it; you invent other solutions.  But when it's already available, it's an elegant pattern.  In my experience, if they have to define it to get it, most people won't bother with the pattern and will retain less elegant solutions.

----------

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


More information about the Python-bugs-list mailing list