[TransWarp] multiple class advisors
Radek Kanovsky
rk at dat.cz
Thu Oct 2 15:59:29 EDT 2003
Hi,
I have a problem with my simple advisor. It shadows protocols.advise
when used both together. Additionally it is order dependent. When I swap
advisors order (myadvisor call is before protocols.advise call), everything
works OK. This is simplified code that fails in adapt call:
from peak.api import *
from protocols.advice import addClassAdvisor
class IInterface (protocols.Interface) :
pass
def myadvisor(a) :
def callback (klass) :
cd = klass.__dict__.copy()
cd['_myadvisor'] = binding.Make(a)
meta = type(klass)
return meta(klass.__name__, klass.__bases__, cd)
addClassAdvisor(callback)
class MyComponent (binding.Component) :
protocols.advise(instancesProvide = [IInterface])
myadvisor(dict)
comp = MyComponent()
acomp = adapt(comp, IInterface) # FAIL
assert comp is acomp
print comp._myadvisor
Can we extend somehow class in class advisors? I am not sure
if extending class with binding in advisor is correct.
Regards,
RadekK
More information about the PEAK
mailing list