[Python-ideas] ``with from`` statement
Andrew Svetlov
andrew.svetlov at gmail.com
Sat Dec 22 18:22:55 CET 2012
More information about the Python-ideas mailing list
Sat Dec 22 18:22:55 CET 2012
- Previous message: [Python-ideas] ``with from`` statement
- Next message: [Python-ideas] ``with from`` statement
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Yes, Nick's proposal is just awesome. I cannot figure out is __exit__ can be generator which use ``yield from`` also inside? On Sat, Dec 22, 2012 at 7:15 PM, Guido van Rossum <guido at python.org> wrote: > 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 >> http://mail.python.org/mailman/listinfo/python-ideas > > > > -- > --Guido van Rossum (python.org/~guido) -- Thanks, Andrew Svetlov
- Previous message: [Python-ideas] ``with from`` statement
- Next message: [Python-ideas] ``with from`` statement
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list