[Python-ideas] Allow "assigning" to Ellipse to discard values.

Ethan Furman ethan at stoneleaf.us
Thu Feb 12 19:15:41 CET 2015


On 02/12/2015 06:58 AM, Rob Cliffe wrote:
> On 11/02/2015 20:06, Greg Ewing wrote:
>> Daniel Holth wrote:
>>> How about zero characters between commas? In ES6 destructing
>>> assignment you'd writes something like ,,c = (1,2,3)
>>
>> Wouldn't play well with the syntax for 1-element tuples:
>>
>>    c, = stuff
>>
>> Is len(stuff) expected to be 1 or 2?
>
> Does that matter?

Yes, it matters.  I have code that had better raise an exception if 'stuff' is not exactly one element.

> In either case the intent is to evaluate stuff and assign its first element to c.

No, its intent is to assign the only element to c, and raise if there are more, or fewer, elements.

> We could have a rule that when the left hand side of an assignment is a tuple that ends in a final comma then unpacking
> stops at the final comma, and it doesn't matter whether there are any more values to unpack.  (Perhaps multiple final
> commas could mean "unpack until the last comma then stop, so
>     c,,, = stuff

a) That's ugly.
b) Special cases aren't special enough to break the rules.

> would mean "raise an exception if len(stuff)<3; otherwise assign the first element of stuff to c".)
> It could even work for infinite generators!

Uh, you're kidding, right?

> But making something "work" instead of raising an exception is likely to break much less code that changing/stopping
> something from "working".

It would break mine, so no thanks.

--
~Ethan~

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150212/e47dab8d/attachment-0001.sig>


More information about the Python-ideas mailing list