[Python-Dev] Any grammar experts?

R. David Murray rdmurray at bitdance.com
Mon Jan 26 03:31:36 CET 2015


On Mon, 26 Jan 2015 01:21:24 +0100, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Sun, 25 Jan 2015 14:59:42 -0800
> Guido van Rossum <guido at python.org> wrote:
> > On Sun, Jan 25, 2015 at 7:32 AM, Georg Brandl <g.brandl at gmx.net> wrote:
> > 
> > > On 01/25/2015 04:08 PM, Antoine Pitrou wrote:
> > > > On Sat, 24 Jan 2015 21:10:51 -0500
> > > > Neil Girdhar <mistersheik at gmail.com> wrote:
> > > >> To finish PEP 448, I need to update the grammar for syntax such as
> > > >>
> > > >> {**x for x in it}
> > > >
> > > > Is this seriously allowed by the PEP? What does it mean exactly?
> > >
> > > It appears to go a bit far.  Especially since you also would have to allow
> > >
> > > {*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.

--David

[*] The *further* generalization...we've already had, for example,
the generalization that allows:

    a, *b = (1, 3, 4)

to work, and that seems very clear to us....now.


More information about the Python-Dev mailing list