[Python-ideas] How assignment should work with generators?
rosuav at gmail.com
Mon Nov 27 16:32:55 EST 2017
On Tue, Nov 28, 2017 at 8:24 AM, Guido van Rossum <guido at python.org> wrote:
> On Mon, Nov 27, 2017 at 1:18 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>
>> Chris Angelico wrote:
>>> The problem is that it depends on internal whitespace to
>>> distinguish it from augmented assignment;
>> Ah, didn't spot that. I guess the ellipsis is the next best
>> thing then.
>> An alternative would be to require parens:
>> (x, y, *) = z
> But that would have the same issue.
> Is this problem really important enough that it requires dedicated syntax?
> Isn't the itertools-based solution good enough? (Or failing that, couldn't
> we add something to itertools to make it more readable rather than going
> straight to new syntax?)
I don't think there's much that can be done without syntax; the
biggest problem IMO is that you need to tell islice how many targets
it'll be assigned into. It needs some interpreter support to express
"grab as many as you have targets for, leaving everything else behind"
without stating how many that actually is. So the question is whether
that is sufficiently useful to justify extending the syntax. There are
a number of potential advantages and several competing syntax options,
and this suggestion keeps coming up, so I think a PEP is warranted.
More information about the Python-ideas