title: Decorate a class in Python by defining the decorator as a class
body: <p>What is a simple example of decorating a class by defining the decorator as a class?</p>
  
  <p>I'm trying to achieve what has been implemented in Python 2.6 using <a href="http://www.python.org/dev/peps/pep-3129/" rel="noreferrer">PEP 3129</a> except using classes not functions as Bruce Eckel explains <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=240845" rel="noreferrer">here</a>.</p>
  
  <p>The following works:</p>
  
  <pre><code>class Decorator(object):
      def __init__(self, arg):
          self.arg = arg
  
      def __call__(self, cls):
          def wrappedClass(*args):
              return cls(*args)
          return type("TestClass", (cls,), dict(newMethod=self.newMethod, classattr=self.arg))
  
      def newMethod(self, value):
          return value * 2
  
  @Decorator("decorated class")
  class TestClass(object):
      def __init__(self):
          self.name = "TestClass"
          print "init %s"%self.name
  
      def TestMethodInTestClass(self):
          print "test method in test class"
  
      def newMethod(self, value):
          return value * 3
  </code></pre>
  
  <p>Except, in the above, wrappedClass is not a class, but a function manipulated to return a class type. I would like to write the same callable as follows:</p>
  
  <pre><code>def __call__(self, cls):
          class wrappedClass(cls):
              def __init__(self):
                  ... some code here ...
          return wrappedClass
  </code></pre>
  
  <p>How would this be done?</p>
  
  <p>I'm not entirely sure what goes into <em>"""... some code here ..."""</em></p>