[Python-ideas] Generator unpacking

Stephen J. Turnbull stephen at xemacs.org
Sun Feb 14 20:23:35 EST 2016


Georg Brandl writes:

 > Assigning to Ellipsis?  Interesting idea, but I'd probably go a bit
 > further in the similarity to star-assignment:
 > 
 >     a, b, *... = value

I don't get the "*".  Normally that means create or unpack a
container, but here the semantics is "leave the container alone".

And to my eyes, it's not an assignment to Ellipsis semantically.  It's
an operator that says "b gets an element, and the tail of value is used
somewhere else, don't copy it as a sequence to b".  Perhaps

    a, b ...= consumable_value

would make that clearer but it looks strange and ugly to me.

What would

    a, b, ... = some_list

mean?  (Using the OP's notation without prejudice to other notations.)
Would it pop a and b off the list?

 > Ellipsis could then be a general "throw-away" lvalue.  This would make it
 > possible to say
 > 
 >     a, ..., b, ... = some_function()
 > 
 > i.e. skip exactly one item in unpacking.

That has a rather different meaning in math texts, though.  It means
"an infinite sequence starting at a with a generic element denoted
'b'".  The number of elements between a and b is arbitrary, and
typically indicated by writing b as an expression involving an index
variable such as i or n.

 > Keep in mind that Ellipsis is also a legal rvalue anywhere else.

That might kill the operator interpretation.



More information about the Python-ideas mailing list