title: Overload a property setter in Python
body: <p>Using Python 3, I want to overload a property setter (add instructions) in a child class.
  The following code seems right, but running it will raise an <code>AttributeError: 'super' object has no attribute 'value'</code>.</p>
  
  <pre><code>class Base(object):
      def __init__(self):
          self._value = 0
  
      @property
      def value(self):
          return self._value
  
      @value.setter
      def value(self, val):
          self._value = val
  
  
  class Child(Base):
      def __init__(self):
          super().__init__()
          self._double = 0
  
      @property
      def value(self):
          # I don't want to rewrite the getter so I call super
          return super().value
  
      @value.setter
      def value(self, val):
          # Get in trouble here
          super().value = val
          self._double = val * 2
  
  
  c = Child()
  c.value  # prints 0
  c.value = 1  # raises error
  </code></pre>
  
  <p>I can't use <code>self.value = val</code> in the overloaded setter because it will cause a <code>RecursionError</code>.</p>
  
  <p>What am I doing wrong?</p>
  
  <p><strong>Edit:</strong> I don't think this question is a duplicate of the mentioned one.
  My question really is: "Can I override a setter in a child class and call the parent one without rewriting the same assignment?"</p>
  
  <p>This is why I'm trying to do <code>super().value = val</code> instead of <code>self._value = val</code>.</p>
  
  <p>Why is <code>return super().value</code> working, and <code>super().value = val</code> isn't?</p>
  
  <h1>Answer</h1>
  
  <p>(Since it's marked as duplicate I can't post an answer so here it is:)</p>
  
  <p>Got the answer here: <a href="https://stackoverflow.com/questions/1021464">How to call a property of the base class if this property is being overwritten in the derived class?</a>.</p>
  
  <p>In short: use <code>Base.value.fset(self, val)</code> instead of <code>super().value = val</code>.</p>
  
  <pre><code>class Child(Base):
      def __init__(self):
          super().__init__()
          self._double = 0
  
      @Base.value.setter
      def value(self, val):
          Base.value.fset(self, val)
          self._double = val * 2
  </code></pre>