PEP 218 Re: ANN: set-0.1 module available
Gonçalo Rodrigues
op73418 at mail.telepac.pt
Sat May 18 12:28:41 EDT 2002
On 18 May 2002 17:15:29 +0200, Bernhard Herzog <bh at intevation.de> wrote:
>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.
Doesn't this mean, in practice, that it is immutable? To me, this
requirement is just shifting responsabilities from one place to the
other and not really solving the problem.
>
>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.
I believe 2. is more stringent:
equal objects iff equal hash values
>
> Bernhard
Best regards,
Gonçalo Rodrigues
More information about the Python-list
mailing list