On Wed, May 18, 2016, 10:12 Ethan Furman <ethan@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@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/