[PEAK] Circular class adapters..
Bob Ippolito
bob at redivi.com
Thu Feb 19 18:34:54 EST 2004
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:
Traceback (most recent call last):
File "./proto.py", line 20, in ?
class Foo(object):
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/site-packages/protocols/advice.py", line 230, in advise
return callback(newClass)
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/site-packages/protocols/api.py", line 219, in callback
provides=classProvides, doesNotProvide=classDoesNotProvide
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/site-packages/protocols/api.py", line 159, in adviseObject
declareAdapterForObject(proto, NO_ADAPTER_NEEDED, ob)
----- cut, it's pages and pages long -------
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/site-packages/protocols/classic.py", line 207, in
declareProvides
if updateWithSimplestAdapter(self.reg, protocol, adapter, depth):
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/site-packages/protocols/adapters.py", line 174, in
updateWithSimplestAdapter
new = minimumAdapter(old,adapter,oldDepth,depth)
RuntimeError: maximum recursion depth exceeded
-bob
More information about the PEAK
mailing list