How can I use descriptors for non-static methods?
<p>I am aware that I can use descriptors to change static property as if it were a normal property. However, when I try using descriptors for a normal class property, I end up changing the object it references to, instead of the value in the object.</p>

<p>If I have</p>

<p>Normal use, considering that the method(param) returns an object</p>

<pre><code>class SomeClass():
    property = method(param)
</code></pre>

<p>I can then do:</p>

<pre><code>instance = SomeClass()
instance.property = 3
</code></pre>

<p>and be able to have that setting handled by the the class of which property is an instance.</p>

<p>Now, if I instead have</p>

<pre><code>class SomeClass():
    def__init__(self):
        self.property = method(param)
</code></pre>

<p>and I do:</p>

<pre><code>instance = SomeClass()
instance.property = 3
</code></pre>

<p>That code does not work, and I overwrite the reference to the object created by method(param) with 3, instead of having that setting handled by the descriptor.</p>

<p>Is there a way I can use descriptors without static methods? In essence, I need to be able to create several instances of the class, each with its own unique properties that can be altered using the convenient descriptor method. Is that possible?</p>

<p>Python version: 2.7</p>

<p>Thanks!</p>

<p>Descriptors provide a simple mechanism for variations on the usual patterns of binding functions into methods.</p>

<p>To recap, functions have a <code>__get__()</code> method so that they can be converted to a method when accessed as attributes. The non-data descriptor transforms an <code>obj.f(*args)</code> call into <code>f(obj, *args)</code>. Calling <code>klass.f(*args)</code> becomes <code>f(*args)</code>.</p>

<p>This chart summarizes the binding and its two most useful variants:</p>

<pre class="lang-none prettyprint-override"><code>Transformation  Called from an Object   Called from a Class
function            f(obj, *args)           f(*args)
staticmethod        f(*args)                f(*args)
classmethod         f(type(obj), *args)     f(klass, *args)
</code></pre>

<p>Static methods return the underlying function without changes. Calling either c.f or C.f is the equivalent of a direct lookup into</p>

<p><code>object.__getattribute__(c, "f") or object.__getattribute__(C, "f").</code>
   As a result, the function becomes identically accessible from either an object or a class.</p>

<p>Good candidates for static methods are methods that do not reference the self variable.</p>

<pre><code>class RevealAccess(object):
    """A data descriptor that sets and returns values
       normally and prints a message logging their access.
    """
    def __init__(self, initval=None, name='var'):
        self.val = initval
        self.name = name

    def __get__(self, obj, objtype):
        print 'Retrieving', self.name
        return self.val

    def __set__(self, obj, val):
        print 'Updating', self.name
        self.val = val

&gt;&gt;&gt; class MyClass(object):
...     x = RevealAccess(10, 'var "x"')
...     y = 5
...
&gt;&gt;&gt; m = MyClass()
&gt;&gt;&gt; m.x
Retrieving var "x"
10
&gt;&gt;&gt; m.x = 20
Updating var "x"
&gt;&gt;&gt; m.x
Retrieving var "x"
20
&gt;&gt;&gt; m.y
5
</code></pre>

python python-2.7