[Python-ideas] Generator unpacking

Georg Brandl g.brandl at gmx.net
Mon Feb 15 03:34:07 EST 2016


On 02/15/2016 09:24 AM, Andrew Barnert via Python-ideas wrote:
> On Feb 14, 2016, at 23:30, Georg Brandl
> <g.brandl at gmx.net> wrote:
>> 
>>> On 02/15/2016 07:31 AM, Andrew Barnert via Python-ideas wrote: On Feb 14,
>>> 2016, at 10:57, Georg Brandl <g.brandl at gmx.net>
>>> wrote:
>> 
>>>> But thinking about it, this is also legal at the moment:
>>>> 
>>>> [] = []
>>> 
>>> Yes, but that's completely different. The [] on the left isn't an
>>> expression, or even a target, but a target list with 0 targets in it.
>>> Assignment to target lists is defined recursively, so assigning to 0
>>> targets is legal iff you're unpacking 0 values.
>>> 
>>> The fact that you have specifically [] on the right side is irrelevant.
>>> You can get the same effect by writing [] = (), or [] = {}, or [] = (i
>>> for i in range(5) if i<0). And clearly, you're not assigning to "the
>>> empty list", because each empty list created with [] is a distinct
>>> object.
>> 
>> Yes, what you're saying can be expressed as "of course it's legal, since
>> it's legal".
> 
> No; common sense isn't the same thing as tautology. It has an obvious
> semantics, there's no good reason to ban it, and it comes for free with the
> simplest grammar--therefore, it's common sense that the language should allow
> it. It's only because Python generally does such a great job following common
> sense that you don't notice. :)
>
> And it's similar common sense that your version of "..." should make "... =
> ..." legal, while Nick's version should make it illegal.

Well, that's all I wanted to express.  If what was noteworthy to me was
all just common sense to you, so much the better. :)  Keep in mind that it
might not be to everyone.

Georg



More information about the Python-ideas mailing list