[Python-ideas] Unpack of sequences

Guido van Rossum guido at python.org
Thu Aug 30 00:21:21 CEST 2012


On Wed, Aug 29, 2012 at 3:10 PM, Mike Graham <mikegraham at gmail.com> wrote:
> On Wed, Aug 29, 2012 at 11:03 AM, Guido van Rossum <guido at python.org> wrote:
>> Also of course assignment has no equivalent to keyword parameters, nor
>> does it (currently) allow a "lone star" -- although it would be handy
>> to be able to say
>>
>> a, b, * = xs
>>
>> as a shorthand for
>>
>> a, b, *_ = xs
>> del _
>
> Is there any good reason not to introduce this syntax?

I should apologize for bringing this up, because the analogy is
actually backwards. (Or maybe I could claim that this backwardness is
a good warning against hypergeneralization. :-)

In function definitions, it actually means *don't allow more
positional arguments*. The equivalent already exists for unpacking
assignment:

a, b = xs

The reason separate syntax is needed in function definitions is that
we occasionally wish to say "and there are no more positional
parameters" but also "but there are some additional keyword-only
parameters".

Until unpacking assignment support an equivalent to keyword parameters
with default values we won't need * there to mean "there should be no
more values". But giving it the *opposite* meaning of "and ignore
subsequent values" would be just perverse given what it means in
function declarations.

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list