davidlmorton/callbacks — pull request #6 by chadrik (2014-08-01 21:57:21+00:00)
Title: Add a prototype for setting up callbacks on a method from a class object

Here you go, this works for adding callbacks at the class- and instance- level. e.g.

```python
class Car(object):
def __init__(self, name, speed):
self.name = name
self.speed = speed

@supports_callbacks
def get_speed(self):
print "getting speed"
return self.speed

# @pre_callback(Car.speed, takes_target_args=True)
def mycallback1(self):
print "how's my driving?"

# @post_callback(Car.speed, takes_target_results=True)
def mycallback2(speed):
if speed < 55:
print "that's pretty slow"
else:
print "nice and fast"

# add to all cars:
Car.get_speed.add_post_callback(mycallback2, takes_target_result=True)

ferrari = Car('ferrari', 180)
truck = Car('truck', 50)

# add to just truck:
truck.get_speed.add_pre_callback(mycallback1, takes_target_args=True)

print "calling ferrari:"
ferrari.get_speed()
print

print "calling truck:"
truck.get_speed()
```

prints:
```
calling ferrari:
getting speed
nice and fast

calling truck:
how's my driving?
getting speed
that's pretty slow
```

It's not perfect, but perhaps that will get you unstuck. If you get the tests running I'll add some to test this case.