PEP 218 Re: ANN: set-0.1 module available

Bernhard Herzog bh at intevation.de
Sat May 18 11:15:29 EDT 2002


Erik Max Francis <max at alcyone.com> writes:

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

It seems to me that the most sensible solution would be to deal with it
like a dictionary deals with mutable keys: By not caring about whether
an object is mutable or not (there is no way to determine this anyway)
but relying on a certain behavior regarding hash values instead.

If an object is stored in a dict as a key, the only things that matter
are that

1. its hash value doesn't change as long as the object is used as a key.

2. equal objects have equal hash values

There may be some more subtle requirements. I'm not sure what happens
when two objects that have the same hash value but do not compare eqal
at first later become equal, for instance.

   Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Sketch                                 http://sketch.sourceforge.net/
MapIt!                                           http://www.mapit.de/



More information about the Python-list mailing list