[Python-ideas] Revised**7 PEP on Yield-From
jh at improva.dk
Thu Mar 19 15:38:26 CET 2009
Greg Ewing wrote:
> I've made another couple of tweaks to the formal semantics
> (so as not to over-specify when the iterator methods are
> looked up).
> Latest version of the PEP, together with the prototype
> implementation and other related material, is available
I am working on my own patch, based on rev2 of yours from the above link
and the algorithm I have been going on about. It is currently working,
and is even slightly faster than yours in every test I have (much faster
in some, that was the whole point). I still need to do a bit of cleanup
before I throw it to the wolves though...
Anyway, I have a few questions/comments to your patch.
1. There is a small refcounting bug in your gen_iternext function. On
success, it returns without decref'ing "yf".
2. In the comment for "gen_undelegate" you mention "certain recursive
situations" where a generator may lose its frame before we get a
chance to clear f_yieldfrom. Can you elaborate? I can't think of
any, and haven't been able to catch any with asserts in a
debug-build using my own patch. However, if they exist I will need
to handle it somehow and knowing what they are would certainly help.
3. It looks like you are not calling "close" properly from "next",
"send" and "throw". This makes no difference when delegating to a
generator (the missing close would be a no-op), but would be an
issue when delegating to a non-generator.
4. It looks like your "gen_close" does not try to throw a
GeneratorExit before calling close when delegating to a
non-generator. I think it should to match the description of
"close" in PEP342 and the expansion in your PEP.
Other than that, great work. It would have taken me ages to figure out
all the necessary changes to the grammar, parser, ... and so on by
myself. In fact I probably wouldn't even have tried.
I hope this helps, and promise to publish my own version of the patch
once I think it is fit for public consumption.
More information about the Python-ideas