[Python-ideas] return value of yield expressions

Nick Coghlan ncoghlan at gmail.com
Wed Sep 14 00:58:06 CEST 2011

On Wed, Sep 14, 2011 at 8:26 AM, David Townshend <aquavitae69 at gmail.com> wrote:
> On Sep 13, 2011 8:53 PM, "Guido van Rossum" <guido at python.org> wrote:
>> On Tue, Sep 13, 2011 at 11:35 AM, Jacob Holm <jh at improva.dk> wrote:
>> > I am not wed to the particular suggested syntax, but I would like to see
>> > the functionality available *somehow* in a way where you don't have to
>> > repeat the sequence of variable names.  And I don't think that is
>> > possible without *some* syntax change.
>> I agree that you can't do this today.
> I've only skimmed this so I might be way off track, but isn't this
> capability (although not the syntax) already covered to an extent by PEP
> 362?

Yep, I was going to mention PEP 362's Signature.bind() as well - the
function signature objects in that PEP are closely tied in to the
issues described in that thread. Sure, you can't easily unpack them
into local variables, but you could fairly easily use them to pass
formatted data into a coroutine.

As far as non-coroutine use cases go, the main benefit (explicitly
mentioned in PEP 362) lies in generating signature details for wrapper
functions that go beyond the current typical "*args, **kwds". A tool
like functools.partial(), for instance, could take the signature
object for the function being wrapped, remove the values already
supplied, and then set the result as the signature for the created

Another Signature.bind() in particular is useful for is in
prevalidating arguments for delayed calls - you can check that the
parameters at least match the function being called immediately, while
deferring the actual invocation of the function until later.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list