title: What makes a user-defined class unhashable?
body: <p>The <a href="http://docs.python.org/py3k/glossary.html#term-hashable" rel="noreferrer">docs</a> say that a class is hashable as long as it defines <code>__hash__</code> method and <code>__eq__</code> method. However:</p>
  
  <pre><code>class X(list):
    # read-only interface of `tuple` and `list` should be the same, so reuse tuple.__hash__
    __hash__ = tuple.__hash__
  
  x1 = X()
  s = {x1} # TypeError: unhashable type: 'X'
  </code></pre>
  
  <p>What makes <code>X</code> unhashable?</p>
  
  <p>Note that I must have identical lists (in terms of regular equality) to be hashed to the same value; otherwise, I will <a href="http://docs.python.org/dev/reference/datamodel.html?highlight=__hash__#object.__hash__" rel="noreferrer">violate this requirement</a> on hash functions:</p>
  
  <blockquote>
    <p>The only required property is that objects which compare equal have
    the same hash value</p>
  </blockquote>
  
  <p>The docs do warn that a hashable object shouldn't be modified during its lifetime, and of course I don't modify instances of <code>X</code> after creation. Of course, the interpreter won't check that anyway.</p>