[Python-Dev] PEP 380 (yield from a subgenerator) comments

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Mar 21 22:54:18 CET 2009


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?

-- 
Greg


More information about the Python-Dev mailing list