[Python-3000] set literals

Guido van Rossum guido at python.org
Mon Jul 10 19:26:53 CEST 2006


On 7/10/06, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Guido van Rossum wrote:
> > I've also sometimes thought of unifying dicts and sets by implementing
> > set operations on the keys of dicts only. When the values aren't the
> > same, we could make an arbitrary decision e.g. the left operand wins.
>
> If the right operand always won then a |= b would be equivalent to a.update(b).

But somehow it seems more reasonable to let the left operand win.
Finally we'd have a way to spell both choices: a |= b and a.update(b).

> > # And of course it would solve the empty set notation problem nicely:
> > assert dict() == {} == set()
>
> So dicts would always start life using the set implementation, and switch to
> the full dict implementation only when a non-None value was added?

No, there would only be one implementation.

> > Unfortunately we couldn't redefine <=, <, >=, > to mean various
> > subset/superset tests without backwards incompatibilities (but does
> > anyone care?
>
> You mean those are defined *now*? I'm trying to figure out what the heck they
> could even mean. . .

They're intended to provide stable though arbitrary ordering for
dicts. Admittedly not very useful (and a pain to implement!). In py3k
we won't require everybody to support <= etc.; while so far I've been
saying this about different types, it makes sense that even within one
type one might not want to define them.

> > I still expect there's a fatal flaw in the scheme, but I can't think
> > of it right now...
>
> If you've got an idea of how to handle the promotion from the set
> implementation to the dict implementation when a non-None value is entered,
> then I can't see any fatal flaws, either.

No promotion is necessary. set() would simply be a different factory
function than dict(). I guess set(x) would equal dict.fromkeys(x). (I
have to admit that I like the set() spelling better. :-) But
type(set()) is dict.

> I'm sure Raymond will be able to come up with something, though :)

Haven't heard from him yet.

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


More information about the Python-3000 mailing list