[Python-ideas] Add contextlib.DummyContext
Brett Cannon
brett at python.org
Wed May 18 13:31:44 EDT 2016
On Wed, May 18, 2016, 10:12 Ethan Furman <ethan at stoneleaf.us> wrote:
> On 05/18/2016 06:16 AM, Giampaolo Rodola' wrote:
> > On Wed, May 18, 2016 at 1:36 AM, Devin Jeanpierre wrote:
>
> >> with contextlib.ExitStack() as exit_stack:
> >> if not bypass_lock:
> >> exit_stack.enter_context(RedisLock())
> >>
> >> And similar.
> >>
> >> In fact, ExitStack can itself be used as a no-op context manager, if
> >> you want.
> >
> > I didn't think about this. So yeah, my proposal is useless. Nevermind.
>
> Not at all. It's a good use-case, and it helped introduce/remind us
> about ExitStack (which I suspect is a hidden gem).
>
> So thank you all! :)
>
Python 3.6 also has a context manager ABC so you could also use that in 2
lines for a dummy context manager.
-brett
> --
> ~Ethan~
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160518/3318e071/attachment.html>
More information about the Python-ideas
mailing list