Huh. There's something funky here that I don't understand. Because I don't have the module functools, I simplified a bit:
class SubDevice(object):
def __init__(self, action):
#always pass a reference to self as first argument
self.action = action # functools.partial(action, self)
self.state = "ready"
def action1(self): #the argument list has to contain self!
if self.state == "ready":
self.state = "error"
else:
self.state = "ready"
a = SubDevice(action1)
a.action() #### <---
print a.state # 'error'
Shockingly, this throws an error:
Traceback (most recent call last):
File "C:/Python24/subdevicetest.py", line 14, in -toplevel-
a.action()
TypeError: action1() takes exactly 1 argument (0 given)
Now, my understanding of the paradigm was that a.action() called the member method with a as the first parameter. Yet ... it doesn't!
When I replace with:
class SubDevice(object):
def __init__(self, action):
#always pass a reference to self as first argument
self.action = action # functools.partial(action, self)
self.state = "ready"
def action1(self): #the argument list has to contain self!
if self.state == "ready":
self.state = "error"
else:
self.state = "ready"
a = SubDevice(action1)
a.action(a) ### <----
print a.state # 'error'
Then it works fine. So yes, I think there is an issue with what you want to do, and no, I don't (yet) know what it is.
Vega, thoughts?
Jeff