title: Interaction of a hashable class with Enum in Python
body: <p>I have defined a class which I am trying to make hashable. Additionally, there's an enum which uses objects of this class as values of its enum members.</p>
  
  <pre><code>from enum import Enum
  
  
  class Dummy(object):
      def __init__(self, name, property_):
          self.name = name             # can only be a string
          self.property = property_    # can only be a string
  
      def __hash__(self):
          # print "Hash called for ", self
          # print("----")
          return hash(self.property)
  
      def __eq__(self, other):
          # print "Eq called for: "
          # print self
          # print other
          return (self.property == other.property)
  
      def __ne__ (self, other):
          return not (self == other)
  
      def __str__(self):
          return (self.name + "$" + self.property)
  
  
  class Property(Enum):
      cool = Dummy("foo", "cool")
      hot = Dummy("bar", "hot")
  </code></pre>
  
  <p>Although this works fine, I noticed -- by un-commenting the <code>print</code> statements -- that the <code>__hash__</code> and <code>__eq__</code> magic methods are invoked for the two enum member values. Why is this so? Aren't these used only during hashing and equality checks?</p>
  
  <p>Additionally, if I change the enum class to the following, all hell breaks loose.</p>
  
  <pre><code>class Property(Enum):
      cool = Dummy("foo", "cool")
      hot = [Dummy("bar-1", "hot-1"), Dummy("bar-2", "hot-2")]
  </code></pre>
  
  <p>The <code>__eq__</code> magic method seems to be called for the <code>Dummy</code> object corresponding to <code>Property.cool</code> and the list corresponding to <code>Property.hot</code>, as evident from the output:</p>
  
  <pre><code>Hash called for  foo$cool
  ----
  Eq called for: 
  foo$cool
  [&lt;__main__.Dummy object at 0x7fd36633f2d0&gt;, &lt;__main__.Dummy object at 0x7fd36633f310&gt;]
  ----
  Traceback (most recent call last):
    File "test.py", line 28, in &lt;module&gt;
      class Property(Enum):
    File "/blah/.local/lib/python2.7/site-packages/enum/__init__.py", line 237, in __new__
      if canonical_member.value == enum_member._value_:
    File "test.py", line 19, in __eq__
      return (self.property is other.property)
  AttributeError: 'list' object has no attribute 'property'
  </code></pre>
  
  <p>Why is this happening? Why are the magic methods called in the first place, and why is <code>__eq__</code> called on a class object and a list?</p>
  
  <p>Please note that this is only a representative example, and the real use-case makes this design -- enum with values as lists of hashable class objects -- appear less weird.</p>