Python ignoring property setter in favor of property getter
<p>I have created a class that has a property with a setter. There are 2 different ways to use this class, so the values of some of the object components may be set in a different order depending on the scenario (i.e. I don't want to set them during <code>__init__</code>). I have included a non-property with its own set function here to illustrate what is and isn't working.</p>

<pre><code>class Dumbclass(object):

  def __init__(self):
    self.name = None
    self.__priority = None

  @property
  def priority(self):
    return self.__priority

  @priority.setter
  def priority(self, p):
    self.__priority = p

  def set_name(self, name):
    self.name = "dumb " + name

  def all_the_things(self, name, priority=100):
    self.set_name(name) 
    self.priority(priority)

    print self.name
    print self.priority
</code></pre>

<p>When I run the following, it returns <code>TypeError: 'NoneType' object is not callable</code>. I investigated with pdb, and found that it was calling the getter instead of the setter at <code>self.priority(priority)</code>.</p>

<pre><code>if __name__ == '__main__':
  d1 = Dumbclass()
  d1.all_the_things("class 1")

  d2 = Dumbclass()
  d2.all_the_things("class 2", 4)
</code></pre>

<p>What's going on here?</p>

<p>Short Answer: Please change your line <code>self.priority(priority)</code> to <code>self.priority = priority</code></p>

<p>Explanation: Setter is called only when you assign something to the attribute. In your code, you are not doing an assignment operation.</p>

<p>Here are some nice references if you want to understand more:</p>

<ol>
<li><a href="http://www.ibm.com/developerworks/library/os-pythondescriptors/" rel="nofollow">Python descriptors</a></li>
<li><a href="http://stackoverflow.com/questions/17330160/how-does-the-property-decorator-work">How does the @property decorator work?</a></li>
<li><a href="http://www.programiz.com/python-programming/property" rel="nofollow">Real Life Example</a></li>
</ol>

python properties