[Python-Dev] PEP 559 - built-in noop()

Nick Coghlan ncoghlan at gmail.com
Thu Nov 23 05:35:29 EST 2017


On 23 November 2017 at 19:42, Chris Jerdonek <chris.jerdonek at gmail.com>
wrote:

> On Wed, Nov 22, 2017 at 4:32 PM, Victor Stinner <victor.stinner at gmail.com>
> wrote:
>
>> Aha, contextlib.nullcontext() was just added, cool!
>>
>
> So is this equivalent to--
>
>     @contextmanager
>     def yielding(x):
>         yield x
>
> I 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 at gmail.com   |   Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171123/ce3bc07e/attachment.html>


More information about the Python-Dev mailing list