[PEAK] How do I resolve AmbiguousMethod?
Phillip J. Eby
pje at telecommunity.com
Fri Jan 26 11:54:27 EST 2007
At 05:06 PM 1/26/2007 +0100, Daniel Nouri wrote:
>What's the best way to do what I want to do?
You can't do it in RuleDispatch without defining a custom method
combination. Even then, it would be difficult, because it sounds like
you're trying to resolve the priority based on something that could change
on each call of the function. RuleDispatch can only handle
statically-determinable rule precedence, i.e., precedences that can be
computed without reference to the *actual* arguments passed to a
function. In other words, given two adapters, if one adapter is preferable
to another on one call of the function, it must be preferable in all cases,
assuming it's applicable.
Without this condition, you would have to create a method combination that
dynamically determines which adapter is more suitable at the time the
function is called. In other words, your method combination would return a
wrapper function to do this.
Personally, my suggestion would be to avoid emulating Zope's adapter system
to begin with. For stateless adapters, you can just use generic functions
to begin with, and a lot of complexity goes away just like that. Try using
the 'simplegeneric' package on the CheeseShop (which, unlike RuleDispatch,
is actively developed and supported), and you'll find that you can do most
of what Zope adapters can do, excluding esoterica such as tuple adapters,
event adapters, etc. (which require something like PEAK-Rules or
RuleDispatch in order to emulate them).
More information about the PEAK