On Sat, Feb 21, 2015 at 9:12 PM, Dawid Crivelli <[email protected]> wrote:

> Moreover, if you put a mutable object into a dict and then change one of
>> its fields and its hash depended on that field value, then it will be
>> "lost" in the sense that if you check for that *same object* being in
>> the dict, it will appear not to be, since it no longer ends up in the same
>> hash bucket.
>
> I had that bite me a few weeks ago, when all the keys in the dictionary
> pointed to the same array, i.e. the last key inserted.  Wouldn't it be
> sensible to copy the mutable keys by default, or at least have some warning
> in the documentation? I've recently learned that Python forbids mutable key
> types for that exact same reason.
>

Well, hashing mutlabe objects by object_id is safe since the identity of an
object cannot change. What is unsafe and what I presume bit you is that we
hash mutable arrays and dicts and such by value rather than by identity. Is
that what you encountered?

Reply via email to