overriding callbacks avoiding attribute pollution
Posted
by pygabriel
on Stack Overflow
See other posts from Stack Overflow
or by pygabriel
Published on 2010-05-13T16:07:33Z
Indexed on
2010/05/13
16:24 UTC
Read the original article
Hit count: 161
python
|asynchronous
I've a class that has some callbacks and its own interface, something like:
class Service:
def __init__(self):
connect("service_resolved", self.service_resolved)
def service_resolved(self, a,b c):
''' This function is called when it's triggered
service resolved signal and has a lot of parameters'''
the connect function is for example the gtkwidget.connect, but I want that this connection is something more general, so I've decided to use a "twisted like" approach:
class MyService(Service):
def my_on_service_resolved(self, little_param):
''' it's a decorated version of srvice_resolved '''
def service_resolved(self,a,b,c):
super(MyService,self).service_resolved(a,b,c)
little_param = "something that's obtained from a,b,c"
self.my_on_service_resolved(little_param)
So I can use MyService by overriding my_on_service_resolved.
The problem is the "attributes" pollution. In the real implementation, Service has some attributes that can accidentally be overriden in MyService and those who subclass MyService.
How can I avoid attribute pollution?
What I've thought is a "wrapper" like approach but I don't know if it's a good solution:
class WrapperService():
def __init__(self):
self._service = service_resolved
# how to override self._service.service_resolved callback?
def my_on_service_resolved(self,param):
'''
'''
© Stack Overflow or respective owner