title: Python decorator for attribute and method?
body: <p>Is it possible to have a decorator that makes a method work like an attribute if values are assigned to it using <code>class.something = 2</code> and work like a method if it is called like <code>class.something(2, True)</code>?</p>
  
  <h1>What I currently have</h1>
  
  <p>To be more concrete, I currently have the following</p>
  
  <pre><code>class attributeSetter(object):
     ''' Makes functions appear as attributes. Takes care of autologging.'''
     def __init__(self, func):
         self.func = func
  
     def __set__(self, obj, value):
         return self.func(obj, value)
  
     def __repr__(self):
         return repr(self.__getattribute__)
  </code></pre>
  
  <p>So with this class with a decorated method:</p>
  
  <pre><code>class myClass(object):
     @attributeSetter  # decorated!
     def myAttrib(self, value, add=False, subtract=False):
         if add:
             value += 2
         if subtract:
             value -= 2
         self.__dict__['myAttrib'] = value
  </code></pre>
  
  <p>I can do this:</p>
  
  <pre><code>instance = myClass()
  instance.myAttrib = 2  # sets the value to 2
  instance.myAttrib *= 4  # now 8
  print instance.myAttrib  # 8
  </code></pre>
  
  <h1>What I want</h1>
  
  <p>But I want, in addition, to be able to do this:</p>
  
  <pre><code>instance.myAttrib(3, add=True)  # now 8 + 3 + 2 = 13
  instance.myAttrib(0, subtact=True)  # now 13 + 0 - 2 = 11
  print instance.myAttrib  # 11
  </code></pre>
  
  <p>My hunch is that I just have to add a <strong>__call__</strong> to the <code>attributeSetter</code> decorator like this:</p>
  
  <pre><code>def __call__(self, *args, **kwargs):
      self.func(*args, **kwargs)
  </code></pre>
  
  <p>but then it won't let me set values using the "=" syntax.</p>
  
  <h1>Why?</h1>
  
  <p>I'm co-developing PsychoPy (a python module for stimulus delivery in psychphysics) and we want do to some processing when each stimulus parameter is set, hence the decorator to avoid setter/getter methods. We log each attribute change by default but in some cases, users want to disable logging of this particular setting with an extra log=False argument, or provide more arguments. Hence it would be nice in those cases if could just use the attribute like a function/method, which it really is in the first place.</p>