[Python-3000] Set literals

Georg Brandl g.brandl at gmx.net
Mon Aug 28 19:44:52 CEST 2006


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...

> 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)

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.

* 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.

Georg



More information about the Python-3000 mailing list