title: Dynamic base class and factories
body: <p>I have following code: </p>
  
  <pre><code>class EntityBase (object) :
      __entity__ = None
  
      def __init__ (self) :
          pass
  
  def entity (name) :
      class Entity (EntityBase) :
          __entity__ = name
  
          def __init__ (self) :
              pass
  
      return Entity
  
  class Smth (entity ("SMTH")) :
      def __init__ (self, a, b) :
          self.a = a
          self.b = b
  
  # added after few comments --&gt;
  def factory (tag) :
      for entity in EntityBase.__subclasses__ () :
          if entity.__entity__ == tag :
              return entity.__subclasses__ ()[0]
  
      raise FactoryError (tag, "Unknown entity")
  
  s = factory ("SMTH") (1, 2)
  print (s.a, s.b)
  # &lt;--
  </code></pre>
  
  <p>Now in factory I can get all subclasses of EntityBase, find concrete subclass for "SMTH" and create it. </p>
  
  <p>Is this valid approach or maybe I something misunderstood and doing wrong?</p>