[PEAK] Circular class adapters..

Phillip J. Eby pje at telecommunity.com
Thu Feb 19 18:39:00 EST 2004


At 06:34 PM 2/19/04 -0500, Bob Ippolito wrote:
>I have a use case where I'd like to have a class adapter chain that can
>be circular in some cases, such as:
>
>from protocols import advise, Interface, Adapter
>class IFoo(Interface):
>     pass
>
>class IBar(Interface):
>     pass
>
>class IBaz(Interface):
>     pass
>
>class AFooBar(Adapter):
>     advise(instancesProvide=[IBar], asAdapterForProtocols=[IFoo])
>
>class ABarBaz(Adapter):
>     advise(instancesProvide=[IBaz], asAdapterForProtocols=[IBar])
>
>class ABazFoo(Adapter):
>     advise(instancesProvide=[IFoo], asAdapterForProtocols=[IBaz])
>
>class Foo(object):
>     advise(classProvides=[IFoo])
>
>class Bar(object):
>     advise(classProvides=[IBar])
>
>class Baz(object):
>     advise(classProvides=[IBaz])
>
>How do I make this work?  Is it not possible, or is this a bug in
>PyProtocols?  With 0.9.2, I get this nasty traceback:

Ugh.  It looks like advising an object (the object itself, as opposed to 
its class) with a circular adapter path doesn't work right.  I have no idea 
why, I'll have to investigate further (and add your example to the tests.

As a workaround in the meantime, you could give each class a metaclass, and 
tell the metaclasses that their instances provide the interfaces, instead 
of telling the class that the class provides the interface.




More information about the PEAK mailing list