[PEAK] PyProtocols: TypeError: Ambiguous adapter choice

Sergey Schetinin maluke at gmail.com
Fri Jul 10 13:13:13 EDT 2009


2009/7/10 luper rouch <luper.rouch at gmail.com>:
> 2009/7/10 Sergey Schetinin <maluke at gmail.com>:
>> 2009/7/10 luper rouch <luper.rouch at gmail.com>:
>>> The following code produces an error:
>>>
>>> TypeError: ('Ambiguous adapter choice', <class
>>> '__main__.FooOneAsFoo'>, <class '__main__.FooTwoAsFoo'>, 2, 2)
>>>
>>> --- code begins ---
>>>
>>> from protocols import Interface, advise
>>>
>>> class IFoo(Interface):
>>>    pass
>>>
>>> class IFooOne(Interface):
>>>    pass
>>>
>>> class IFooTwo(Interface):
>>>    pass
>>>
>>> class FooOneAsFoo(object):
>>>    advise(
>>>            instancesProvide=[IFoo],
>>>            asAdapterForProtocols=[IFooOne]
>>>        )
>>>
>>> class FooTwoAsFoo(object):
>>>    advise(
>>>            instancesProvide=[IFoo],
>>>            asAdapterForProtocols=[IFooTwo]
>>>        )
>>>
>>> class ComposedFoo(object):
>>>    advise(
>>>            instancesProvide=[IFooOne, IFooTwo]
>>>        )
>>>
>>> --- code ends ---
>>>
>>> Why is it ambiguous to write for example:
>>>
>>> foo = FooOneAsFoo(ComposedFoo())
>>>
>>> foo has an IFoo interface, adapted from the IFooOne interface of ComposedFoo.
>>> _______________________________________________
>>> PEAK mailing list
>>> PEAK at eby-sarna.com
>>> http://www.eby-sarna.com/mailman/listinfo/peak
>>>
>> Are you sure it's the "foo = FooOneAsFoo(ComposedFoo())" producing the
>> error? Could it actually be IFoo(ComposedFoo()) ?
>>
>
> Actually it's the ComposedFoo definition that triggers the error.
>

I guess I'm wrong, but I remember adapter graph being checked for
ambiguity when used, not on declarations. PEAK-Rules rebuilds indexes
when first used, so maybe that's what I'm confusing it with.

Anyway, the adaptation graph is ambiguous, because there are two
adapters from ComposedFoo type to IFoo protocol with the same weight.
I'm still not sure why you get the error if not trying to do that
adaptation.


More information about the PEAK mailing list