[Python-Dev] PEP 218 (sets); moving set.py to Lib

Guido van Rossum guido@python.org
Mon, 19 Aug 2002 16:38:41 -0400


> [Guido van Rossum]
> > OTOH what then to do with _sort_repr -- make it a class var or an
> > instance var?

[Brett C]
> Well, how often can you imagine someone printing out a single set sorted,
> but having other sets that they didn't want printed out sorted?  I would
> suspect that it is going to be a very rare case when someone wants just
> part of their sets printing sorted and the rest not.
> 
> I say make it a class var.

Hm, but what if two different library modules have conflicting
requirements?  E.g. module A creates sets of complex numbers and must
have sort_repr=False, while module B needs sort_repr=True for
user-friendliness (or because it relies on this).

My current approach (now in CVS!) is to remove the sort_repr flag to
the constructor, but to provide a method that can produce a sorted or
an unsorted representation.  __repr__ will always return the items
unsorted, which matches what repr(dict) does.  After all, I think it
could be confusing to a user when 'print s' shows

    Set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

but

    for i in s: print i,

prints

    9 8 7 6 5 4 3 2 1 0

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