[Python-ideas] Fwd: unpacking generalisations for list comprehension

Nick Coghlan ncoghlan at gmail.com
Tue Oct 11 12:06:50 EDT 2016


On 11 October 2016 at 23:50, אלעזר <elazarg at gmail.com> wrote:
> I thought about it a lot recently. Specifically on your proposal, and in
> general. Unpacking expression can have a much more uniform treatment in the
> language, as an expression with special "bare tuple" type - like tuple, but
> "without the braces".

That's a recipe for much deeper confusion, as it would make "*expr"
and "*expr," semantically identical

   >>> *range(3),
   (0, 1, 2)

As things stand, the above makes tuple expansion the same as any other
expression: you need a comma to actually make it a tuple. If you allow
a bare "*" to imply the trailing comma, then it immediately becomes
confusing when you actually *do* have a comma present, as the "*" no
longer implies a new tuple, it gets absorbed into the surrounding one.
That's outright backwards incompatible with the status quo once you
take parentheses into account:

    >>> (*range(3)),
    (0, 1, 2)

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list