[Python-ideas] ``with from`` statement

Guido van Rossum guido at python.org
Sat Dec 22 18:15:00 CET 2012


Nick already proposed "with (yield from ...): ..."

Maybe in 3.4 we can tweak the syntax so the paresns are not needed.

I am quite glad that we had the foresight (when we designed 'with') to make
this possible.

On Saturday, December 22, 2012, Andrew Svetlov wrote:

> Crazy idea.
> Guido van Rossum mentioned after working on PEP 3156 that context
> managers cannot use
> yield from statement inside __enter__ and __exit__ magic methods.
> Explicit call for entering and leaving context (for locking for
> example) is not convenient.
>
> What do you think about
>
> with from f():
>    do_our_work()
>
>
> ``with from ...` construction calls __enter_from__ generator  and
> iterates via ``yield from`` for that.
> Returned value is our context manager.
>
> The same for __exit_from__ — do``yield from`` for that and stop on
> StopIteration or exception.
>
> --
> Thanks,
> Andrew Svetlov
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org <javascript:;>
> http://mail.python.org/mailman/listinfo/python-ideas
>


-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20121222/9fc08254/attachment.html>


More information about the Python-ideas mailing list