[Python-ideas] Revised**12 PEP on Yield-From

Jim Pryor lists+python-ideas at jimpryor.net
Sat Apr 25 18:10:11 CEST 2009


I created a pure Python decorator-based implementation of PEP 380, based
on the semantics in this latest draft (Revised**12).

There's a "simple" version and an "optimized" version: the simple
version is easier to follow; the optimized version does special handling
for nested yield from calls.

They're both now posted at ActiveState:

http://code.activestate.com/recipes/576727/
http://code.activestate.com/recipes/576728/

>From the descriptions:

> <http://www.python.org/dev/peps/pep-0380/> proposes new syntax ("yield
> from") for generators to delegate control to a "subgenerator" (really to
> any iterator). Any send/next/throw/close calls to the delegating
> generator are forwarded to the delegee, until the delegee is exhausted.
> 
> This is being considered for inclusion in Python 2.7, but I wanted a
> way to play around with the design pattern now (and in case the PEP
> isn't soon accepted, and on older Python installations regardless of
> what happens with future versions of Python).
> 
> So I came up with this decorator-based solution. The "supergenerator"
> decorator wraps the delegating generator with a control handler that
> takes care of directing send/next/throw/close calls to the delegator or
> delegee, as appropriate.

Hope others find them a useful contribution. Of course, I welcome any
feedback.


-- 
Jim Pryor
profjim at jimpryor.net



More information about the Python-ideas mailing list