[Python-ideas] Alternative name for yield-from

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Feb 18 21:22:24 CET 2009


I've had another idea about what to call yield-from:

   y = pass g(x)

which means "run this generator, passing through
any sent/yielded values etc." It's short, it's
suggestive, it doesn't use any new keywords, and
there's no danger of confusing it with 'yield'.

Now, you're probably reaching for the -1 button
at this point, thinking "WTF? That's completely
different from the existing meaning of pass!"

But there's a sense in which the existing 'pass'
can be seen as a degenerate case. Consider the
generator

   def nada():
     if False:
       yield

Since it never yields anything, doing

   pass nada()

is effectively a no-op. Thus, 'pass' with no
generator at all is a no-op as well.

There's still one remaining difference -- the
presence of 'pass' with a value would make the
containing function into a generator, whereas
plain 'pass' wouldn't. We'd just have to live
with that inconsistency.

-- 
Greg



More information about the Python-ideas mailing list