title: Python metaclass to generate correct enum values for class
body: <p>My <a href="https://stackoverflow.com/questions/25518988/python-equivalent-of-c-sharp-enum-hasflag">previous question</a> asked about Enum in python</p>
  
  <p>Lets say I am creating State classes:</p>
  
  <pre><code>class State(object):
      """
      Abstract class representing a state.
      """
      enum = 1
  
      def __init__(self, instance):
          self.instance = instance
  
      def is_flag(self, flag):
          return flag &amp; self.enum == self.enum
  </code></pre>
  
  <p>And then I create different actual States</p>
  
  <pre><code>class New(State):
      enum = 2
      def pay(self):
          ...
  
  class Paid(State):
      enum = 4
      def complete(self):
          ...
  
  class Completed(State):
      enum = 8
  
  
  ACCOUNTABLE = Paid.enum | Completed.enum
  </code></pre>
  
  <p>while this works, I would like to automate the generation of the enum values, and it seems like it can be done by using Meta classes, the question is how?</p>