[Python-Dev] Any grammar experts?

Barry Warsaw barry at python.org
Mon Jan 26 15:43:26 CET 2015


On Jan 25, 2015, at 09:31 PM, R. David Murray wrote:

>> > > {*x for x in it}
>> > >
>> > > which is a set comprehension, while the other is a dict comprehension :)
>> > >
>> > 
>> > That distinction doesn't bother me -- you might as well claim it's
>> > confusing that f(*x) passes positional args from x while f(**x) passes
>> > keyword args.
>> > 
>> > And the varargs set comprehension is similar to the varargs list
>> > comprehension:
>> > 
>> > [*x for x in it]
>> > 
>> > If `it` were a list of three items, this would be the same as
>> > 
>> > [*it[0], *it[1], *it[2]]
>> 
>> I find all this unreadable and difficult to understand.
>
>I did too, before reading the PEP.
>
>After reading the PEP, it makes perfect sense to me.  Nor is the PEP
>complicated...it's just a matter of wrapping your head around the
>generalization[*] of what are currently special cases that is going on
>here.

It does make sense after reading the PEP but it also reduces the readability
and instant understanding of any such code.  This is head-scratcher code that
I'm sure I'd get asked about from folks who aren't steeped in all the dark
corners of Python.  I don't know if that's an argument not to adopt the PEP,
but it I think it would be a good reason to recommend against using such
obscure syntax, unless there's a good reason (and good comments!).

Cheers,
-Barry


More information about the Python-Dev mailing list