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

2017年11月23日 02:38:32 -0800

On 23 November 2017 at 19:42, Chris Jerdonek <[email protected]>
wrote:
> On Wed, Nov 22, 2017 at 4:32 PM, Victor Stinner <[email protected]>
> 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 | [email protected] | Brisbane, Australia
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to