[Python-3000] Set literals

Guido van Rossum guido at python.org
Mon Aug 28 20:55:30 CEST 2006


On 8/28/06, Georg Brandl <g.brandl at gmx.net> wrote:
> Guido van Rossum wrote:
> > On 8/28/06, Georg Brandl <g.brandl at gmx.net> wrote:
> >> At python.org/sf/1547796, there is a preliminary patch for Py3k set literals
> >> as specified in PEP 3100.
> >
> > Very cool! This is now checked in.
>
> Wow, that's fast...

Well it passed all unit tests and the rules for the py3k branch are a
bit looser than for the head... :)

> > Georg, can you do something about repr() of an empty set? This
> > currently produces "{}" while it should produce "set()".
>
> Right, forgot about that case. I'll correct that now.
> (Grr, I even mindlessly changed the unittest that would have caught it)

Checkin?

> In the meantime, I played around with the peepholer and tried to copy
> the "for x in tuple_or_list" optimization for sets. Results are in SF
> patch #1548082.
>
> >> Set comprehensions are not implemented.
> >
> > ETA?
>
> There are some points I'd like to have clarified first:
>
> * would it be wise to have some general listcomp <-> genexp
>    cleanup first? This starts with the grammar, which currently is slightly
>    different (see Grammar:79), and it looks like there's quite a lot of
>    (almost) duplicated code in ast.c and compile.c too.

I expec this cleanup to be quite a bit of work since the semantics are
seriously different. ([...] uses the surrounding scope for the loop
control variables.)

However you might be able to just cleanup the grammar so they are
identical, that would be simpler I suspect.

> * list comprehensions are special-cased because of the LIST_APPEND opcode.
>    If there isn't going to be a special-cased SET_ADD, it's probably the
>    easiest thing to transform {x for x in a} into set(x for x in a) in the
>    AST step, with "set" of course always being the builtin set.

Right. That might actually become a prototype for how to the list
translation as well.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list