[PEAK] How do I resolve AmbiguousMethod?
Daniel Nouri
daniel.nouri at gmail.com
Fri Jan 26 11:06:13 EST 2007
I've played around a bit with RuleDispatch today. Basically, I wanted to
implement Zope's adaptation with RuleDispatch, which was pretty straight
forward, until I came to the point where I had two adapters that would both
fit my criteria.
My first generic function factory looked like this:
def provideAdapter(adapter):
@_do_adapt.when(
"issubclass(adapter.implements, interface) and "
"issubclass(obj.implements, adapter.adapts)")
def adaptor(obj, interface):
return adapter(obj)
However, if I register two adapters (by calling provideAdapter), where one
provides a more specialized interface (interface B(A)) than the other
(interface A), and I request adaptation to A, I want the other adapter, i.e.
the one for interface A, to be returned.
I went along and implemented a function base_distance that returns the
distance between a class A and a class B in the class hierarchy. Now I'd
like to be able to express this:
"issubclass(adapter.implements, interface) and "
"base_distance(obj.implements, adapter.adapts) >= 0"
and somehow imply that the smaller base_distance, the better. That is, if
base_distance is 0 for one function and 3 for another, the first one should
be picked. I tried to look into RuleDispatch's interfaces.py, but got stuck.
What's the best way to do what I want to do?
You can the source code of my experiment here:
http://danielnouri.org/dev/file/scratch/experiments/adaptation_with_gf.py
TIA,
Daniel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: daniel.nouri.vcf
Type: text/x-vcard
Size: 138 bytes
Desc: not available
Url : http://www.eby-sarna.com/pipermail/peak/attachments/20070126/591f48b9/daniel.nouri.vcf
More information about the PEAK
mailing list