[Python-Dev] PEP 351, the freeze protocol

Oren Tirosh orent at hishome.net
Mon Oct 31 18:28:26 CET 2005


On 10/31/05, Antoine Pitrou <solipsis at pitrou.net> wrote:
>
> > It allows everything in Python to be both mutable and hashable,
>
> I don't understand, since it's already the case. Any user-defined object
> is at the same time mutable and hashable.

By default, user-defined objects are equal iff they are the same
object, regardless of their content. This makes mutability a
non-issue.

If you want to allow different objects be equal you need to implement
a consistent equality operator (commutative, etc), a consistent hash
function and ensure that any attributes affecting equality or hash
value are immutable. If you fail to meet any of these requirements and
put such objects in dictionaries or sets it will result in undefined
behavior that may change between Python versions and implementations.

  Oren


More information about the Python-Dev mailing list