On Sat, Mar 21, 2009 at 2:54 PM, Greg Ewing <greg.ew...@canterbury.ac.nz> wrote: > Antoine Pitrou wrote: > >> Do we really want to add a syntactic feature which has such a complicated >> expansion? I fear it will make code using "yield from" much more difficult >> to >> understand and audit. > > As I've said before, I don't think the feature itself is > difficult to understand. You're not meant to learn about > it by reading the expansion -- that's only there to pin > down all the details for language lawyers. > > For humans, almost all the important information is > contained in one paragraph near the top: > > "When the iterator is another generator, the effect is the same as if > the body of the subgenerator were inlined at the point of the ``yield > from`` expression. Furthermore, the subgenerator is allowed to execute > a ``return`` statement with a value, and that value becomes the value of > the ``yield from`` expression." > > Armed with this perspective, do you still think there will > be difficulty in understanding or auditing code?
Well, hmm... I've been out of the loop due to other commitments (sorry), but I really don't like to have things whose semantics is defined in terms of code inlining -- even if you don't mean that as the formal semantics but just as a mnemonic hint. It causes all sorts of confusion about scopes. What happened to the first-order approximation "yield from X" means roughly the same as "for _x in X: yield x" ? The more specialized semantics in some cases can probably be put off until later in the document. FWIW I am okay with the notion that if the immediate subiterator returns a value, that value becomes the value of the yield-from-expression. Suitable semantics that make this effect pass through multiple layers of sub-iterators are fine too. But the exact semantics in the light of try/except or try/finally blocks on the stack are incredibly (perhaps impossibly) tricky to get right -- and it probably doesn't matter all that much what exactly happens as long as it's specified in sufficient detail that different implementations behave the same way (apart from obvious GC differences, alas). -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com