title: Python Enums across Modules
body: <p>Why can in Python 3 enum equality not be checked correctly across module boundaries if the enum has been defined in the main module? Here is an example:</p>
  
  <p>moduleA.py: </p>
  
  <pre><code>#!/usr/bin/python3
  
  import moduleB
  from enum import Enum, unique
  
  @unique
  class MyEnum(Enum):
      A = 1
      B = 2
      # def __eq__(self,other):
      #     assert isinstance(other,self.__class__)
      #     return self.value == other.value
  
  if __name__ == "__main__":
  
      myVar = MyEnum.B
      moduleB.doStuff(myVar)
  </code></pre>
  
  <p>moduleB.py:</p>
  
  <pre><code>#!/usr/bin/python3
  
  import moduleA
  
  def doStuff(aVariable):
      bVariable = moduleA.MyEnum.B
      assert aVariable == bVariable
  </code></pre>
  
  <p>Calling "<em>./moduleA.py</em>" on the command line yields:</p>
  
  <pre><code>Traceback (most recent call last):
    File "./moduleA.py", line 17, in &lt;module&gt;
      moduleB.doStuff(myVar)
    File "/home/ruedi/Dropbox/Reps/stuffed/sosy/testing/moduleB.py", line 7, in doStuff
      assert aVariable == bVariable
  AssertionError
  </code></pre>
  
  <p>Uncommenting the custom equality operator in the enum leads to an assertion failure there. I've found that the class module is not the same in both cases, as it is "__main__" in one case. </p>
  
  <p>What is the most "Pythonic way" to fix this problem (other than moving the enum to its own module)?</p>
  
  <p><strong>EDIT:</strong> Switching to "aVariable is bVariable" does not work either:</p>
  
  <pre><code>Traceback (most recent call last):
    File "./moduleA.py", line 17, in &lt;module&gt;
      moduleB.doStuff(myVar)
    File "/home/ruedi/Dropbox/Reps/stuffed/sosy/testing/moduleB.py", line 7, in doStuff
      assert aVariable is bVariable
  AssertionError
  </code></pre>