title: Class-based decorator and repr() conservation
body: <p>I was trying to have my class-based decorator keeping the <code>repr()</code> behavior of the original wrapped function (to match the way the <code>functools.wraps</code> decorator works on functions). I am using python 3.3.</p>
  
  <p>First I tried functools:</p>
  
  <pre><code>import functools
  
  class ClassBasedDecorator():
      def __init__(self, fn):
          self.fn = fn
          functools.update_wrapper(self, fn)
      def __call__(self, *args, **kwargs):
          self.fn(*args, **kwargs)
  
  @ClassBasedDecorator
  def wrapped(text):
      pass
  </code></pre>
  
  <p>But when I call <code>repr()</code> on the decorated function, I get:</p>
  
  <pre><code>&gt;&gt;&gt; repr(wrapped)
  '&lt;__main__.ClassBasedDecorator object at 0x2d8860b6850&gt;'
  </code></pre>
  
  <p>Very well, so I tried to customize the <code>__repr__</code> method of my decorator, which is supposed to be called by <code>repr()</code>.</p>
  
  <p>Using functools again:</p>
  
  <pre><code>class ClassBasedDecorator():
      def __init__(self, fn):
          self.fn = fn
          functools.update_wrapper(
              self, fn,
              assigned=functools.WRAPPER_ASSIGNMENTS + ('__repr__',)
          )
      def __call__(self, *args, **kwargs):
          self.fn(*args, **kwargs)
  </code></pre>
  
  <p>Doesn't change the output, but something interesting happens:</p>
  
  <pre><code>&gt;&gt;&gt; repr(wrapped)
  '&lt;__main__.ClassBasedDecorator object at 0x2d8860b69d0&gt;'
  &gt;&gt;&gt; wrapped.__repr__()
  '&lt;function wrapped at 0x2d8860a9710&gt;'
  </code></pre>
  
  <p>Explicitly setting the <code>__repr__</code> method of the decorator instance has the same effect.</p>
  
  <p>After a little more tests I deduced <code>repr(instance)</code> actually calls <code>instance.__class__.__repr__(instance)</code>. Thus the overriden <code>__repr__</code> method of the instance is never called.</p>
  
  <hr>
  
  <p>So here are my questions:</p>
  
  <ul>
  <li>Why does <code>repr(instance)</code> call the <code>instance.__class__.__repr__(instance)</code> instead of <code>instance.__repr__()</code>? Or have I missed something else?</li>
  <li>How would you fully reproduce what <code>functools.wraps</code> does with function-based decorators to class-based decorators (including altering the result of <code>repr()</code> calls on the decorated function)?</li>
  </ul>