On Sun, Oct 2, 2016 at 5:07 AM, Neil Girdhar <[email protected]> wrote:
> I suggest a more compact notation:
>
>     with cm_function() as cm if condition:
>         suite()
>

The simplest way would be to make a conditional version of the context manager.

@contextlib.contextmanager
def maybe_cm(state):
    if state:
        with cm_function() as cm:
            yield cm
    else:
        yield None

I believe that'll work.

ChrisA
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to