[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/interface/ Fixed a bug reported by James Knight. Adapter registries sometimes

Jim Fulton jim at zope.com
Thu Jan 13 12:13:22 EST 2005


Log message for revision 28828:
  Fixed a bug reported by James Knight.  Adapter registries sometimes
  failed to reflect declaration changes.
  

Changed:
  U   Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/interface/tests/test_adapter.py

-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.py	2005-01-13 17:13:21 UTC (rev 28827)
+++ Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.py	2005-01-13 17:13:22 UTC (rev 28828)
@@ -123,6 +123,7 @@
 
     def __init__(self, spec, registry):
         self.spec = spec.weakref()
+        self.registry = registry
         spec.subscribe(self)
         self.adapters = {}
         self.dependents = weakref.WeakKeyDictionary()
@@ -137,10 +138,24 @@
             del self.selfImplied
             del self.multImplied
             del self.get
+
+        bases = [self.registry.get(base) for base in self.spec().__bases__]
+        if bases != self.__bases__:
+            # Our bases changed. unsubscribe from the old ones
+            # and subscribe to the new ones
+            for base in self.__bases__:
+                base.unsubscribe(self)
+
+            self.__bases__ = bases
+            for base in bases:
+                base.subscribe(self)
+
         for dependent in self.dependents.keys():
             dependent.dirty()
 
     def clean(self):
+            
+
         self.selfImplied, self.multImplied = adapterImplied(self.adapters)
 
         implied = {}

Modified: Zope3/branches/ZopeX3-3.0/src/zope/interface/tests/test_adapter.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/interface/tests/test_adapter.py	2005-01-13 17:13:21 UTC (rev 28827)
+++ Zope3/branches/ZopeX3-3.0/src/zope/interface/tests/test_adapter.py	2005-01-13 17:13:22 UTC (rev 28828)
@@ -177,7 +177,31 @@
     1
     """
 
+def test_changing_declarations():
+    """
 
+    If we change declarations for a class, those adapter lookup should
+    eflect the changes:
+
+    >>> class I1(zope.interface.Interface):
+    ...     pass
+    >>> class I2(zope.interface.Interface):
+    ...     pass
+
+    >>> registry = AdapterRegistry()
+    >>> registry.register([I1], I2, '', 42)
+
+    >>> class C:
+    ...     pass
+
+    >>> registry.lookup([zope.interface.implementedBy(C)], I2, '')
+
+    >>> zope.interface.classImplements(C, I1)
+
+    >>> registry.lookup([zope.interface.implementedBy(C)], I2, '')
+    42
+    """
+
 def test_suite():
     from zope.testing.doctestunit import DocFileSuite
     return unittest.TestSuite((



More information about the Zope3-Checkins mailing list