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