title: How to implement a good __hash__ function in python
body: <p>When implementing a class with multiple properties (like in the toy example below), what is the best way to handle hashing?</p>
  
  <p>I guess that the <code>__eq__</code> and <code>__hash__</code> should be consistent, but how to implement a proper hash function that is capable of handling all the properties?</p>
  
  <pre><code>class AClass:
    def __init__(self):
        self.a = None
        self.b = None
  
    def __eq__(self, other):
        return other and self.a == other.a and self.b == other.b
  
    def __ne__(self, other):
      return not self.__eq__(other)
  
    def __hash__(self):
        return hash((self.a, self.b))
  </code></pre>
  
  <p>I read on <a href="https://stackoverflow.com/questions/654128/python-hash-functions">this question</a> that tuples are hashable, so I was wondering if something like the example above was sensible. Is it?</p>