PEP 218 Re: ANN: set-0.1 module available

Erik Max Francis max at alcyone.com
Sat May 18 01:04:25 EDT 2002


"James J. Besemer" wrote:

> I wonder if you are perhaps too deeply attached to a particular
> implementation?

I'm going by what seems to me the most straightforward implementation,
which is also what is described in the PEP itself (with the caveat that
the PEP allows sets to contain sets through a tweak).  It seems the most
sensible tradeoff between idealization and practicality.

> I hadn't considered the implication of mutable objects as set members. > If
> you allow an arbitrary list/tree structure to be members, how do you
> decide
> if it's in the set or not? You only consider the list object itself
> or do
> you look at its overall value?


Presumably by an equality test (which can be reflected in the immutable
case by having hashes of equal objects, such as 1 and 1.0, be themselves
equal).

That's not the half of it.  Mutable objects can dynamically change
state, completely outside the control of the container.  So the hard
question is:  What happens when a mutable object changes its value, such
that it effects the arrangement of the set?  How does the container get
notified of this change (which as far as I know there is no standard way
to test in Python), and what happens when a value collision occurs
within the set?  Does one object get disposed?  If so, which one?

These are precisely the same kind of issues that lead one to conclude
that you're much better off with immutable dictionary keys.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Who'd ever think it / Such a squalid little ending
\__/ The American and Florence, _Chess_
    Church / http://www.alcyone.com/pyos/church/
 A lambda calculus explorer in Python.



More information about the Python-list mailing list