[Python-ideas] How assignment should work with generators?

Chris Angelico rosuav at gmail.com
Mon Nov 27 09:01:01 EST 2017

On Tue, Nov 28, 2017 at 12:44 AM, Daniel Moisset
<dmoisset at machinalis.com> wrote:
> On 27 November 2017 at 06:40, Chris Angelico <rosuav at gmail.com> wrote:
>> Here are a few syntaxes that I believe have been proposed at various
>> times:
>> x, y = islice(iter, 2) # status quo
>> x, y = iter # your proposal
>> x, y, = iter # omit last destination
> Just to clear the list, this one (trailing comma) would be
> ambiguous/backward incompatible for the 1 variable case:
> x, = iter
> which is a relatively common idiom and is expected to raise an error if the
> iterator has trailing elements.

Correct. For that and other reasons, I am not in favour of either of
these two proposals. And the status quo is noisy and has duplicated
information (you have to match the ", 2" to the number of assignment
targets). I would support any syntax that (a) is currently illegal,
(b) reads reasonably well, and (c) can't be TOO easily confused with
something else. Assigning to Ellipsis (with or without a star) is my
current preferred, but I'd happily support others that do the same


More information about the Python-ideas mailing list