title: How to implement __iadd__ for a Python property
body: <p>I'm trying to create a Python property where in-place adding is handled by a different method than retrieving the value, adding another value and reassigning. So, for a property <code>x</code> on an object <code>o</code>,</p>
  
  <pre><code>o.x += 5
  </code></pre>
  
  <p>should work differently than</p>
  
  <pre><code>o.x = o.x + 5
  </code></pre>
  
  <p>The value of <code>o.x</code> should be the same in the end, so as not to confuse people's expectations, but I want to make the in-place add more efficient. (In reality the operation takes a lot more time than simple addition.)</p>
  
  <p>My first idea was to define, in the class,</p>
  
  <pre><code>x = property(etc. etc.)
  x.__iadd__ = my_iadd
  </code></pre>
  
  <p>But this raises an AttributeError, presumably because <code>property</code> implements <code>__slots__</code>?</p>
  
  <p>My next attempt uses a descriptor object:</p>
  
  <pre><code>class IAddProp(object):
      def __init__(self):
          self._val = 5
  
      def __get__(self, obj, type=None):
          return self._val
  
      def __set__(self, obj, value):
          self._val = value
  
      def __iadd__(self, value):
          print '__iadd__!'
          self._val += value
          return self
  
  class TestObj(object):
      x = IAddProp()
      #x.__iadd__ = IAddProp.__iadd__  # doesn't help
  
  &gt;&gt;&gt; o = TestObj()
  &gt;&gt;&gt; print o.x
  5
  &gt;&gt;&gt; o.x = 10
  &gt;&gt;&gt; print o.x
  10
  &gt;&gt;&gt; o.x += 5  # '__iadd__!' not printed
  &gt;&gt;&gt; print o.x
  15
  </code></pre>
  
  <p>As you can see, the special <code>__iadd__</code> method is not called. I'm having trouble understanding why this is, although I surmise that the object's <code>__getattr__</code> is somehow bypassing it.</p>
  
  <p>How can I do this? Am I not getting the point of descriptors? Do I need a metaclass?</p>