[Python-ideas] x=(yield from) confusion [was:Yet another alternative name for yield-from]

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Apr 12 01:15:24 CEST 2009

Jacob Holm wrote:

> Except you now have one extra function for exactly the same task, just 
> with a different calling convention.

I don't see anything wrong with that. If you look in the
stdlib, there are plenty of places where alternative APIs
are provided for the same functionality, e.g. in the re
module you have the module-level functions as well as the
match object methods.

I would rather have a couple of functions written in a
straightforward way than rely on a magic wrapper to
artificially munge them into one. Transparent is better
than opaque.

> The "suppress initial next()" feature *would* have helped, by enabling 
> you to write a generic wrapper to use at the call site that could do 
> exactly that.

Now you're just moving the wrappers from one place to
another. I can write a wrapper to convert any lookahead
taking parsing function into a non-lookahead one:

   def expect(f):
     first = yield
     return yield from f(first)

So at the cost of just one extra function, I can call
any of my parsing functions using either style.


More information about the Python-ideas mailing list