(original) (raw)
On 23 November 2017 at 19:42, Chris Jerdonek <chris.jerdonek@gmail.com> wrote:
On Wed, Nov 22, 2017 at 4:32 PM, Victor Stinner <victor.stinner@gmail.com> wrote:Aha, contextlib.nullcontext() was just added, cool!So is this equivalent to--@contextmanagerdef yielding(x):yield xI thought we were against adding one-line functions?
There's a lot of runtime complexity hiding behind that "@contextmanager" line, so I'm open to \`contextlib\` additions that make it possible for sufficiently common patterns to avoid it. (The explicit class based nullcontext() implementation is 7 lines, the same as contextlib.closing())
After 7+ years, I'm happy that this one comes up often enough to be worth a more obvious standard library level answer than we'd previously offered. https://bugs.python.org/issue10049#msg281556 captures the point where I really started changing my mind.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia