[Checkins] SVN: zope.interface/trunk/ Fixed bug https://bugs.launchpad.net/zope3/+bug/109980.

Jim Fulton jim at zope.com
Tue May 22 14:39:49 EDT 2007


Log message for revision 75894:
  Fixed bug https://bugs.launchpad.net/zope3/+bug/109980.
  
  The registry code should always use identity tests to test whether an
  object is already in the registry so as not to run afoul of custom
  comparison methods.
  

Changed:
  U   zope.interface/trunk/CHANGES.txt
  U   zope.interface/trunk/src/zope/interface/adapter.py
  U   zope.interface/trunk/src/zope/interface/tests/test_adapter.py

-=-
Modified: zope.interface/trunk/CHANGES.txt
===================================================================
--- zope.interface/trunk/CHANGES.txt	2007-05-22 18:28:27 UTC (rev 75893)
+++ zope.interface/trunk/CHANGES.txt	2007-05-22 18:39:49 UTC (rev 75894)
@@ -2,6 +2,17 @@
 ******************************
 
 ===========================================
+3.4.0b3 (2007/05/22)
+===========================================
+
+Bug Fixes
+=========
+
+- Objects with picky custom comparison methods couldn't be added to
+  component registries.  Now, when checking whether an object is
+  already registered, identity comparison is used.
+
+===========================================
 3.3.0.1 (2007/01/03)
 ===========================================
 

Modified: zope.interface/trunk/src/zope/interface/adapter.py
===================================================================
--- zope.interface/trunk/src/zope/interface/adapter.py	2007-05-22 18:28:27 UTC (rev 75893)
+++ zope.interface/trunk/src/zope/interface/adapter.py	2007-05-22 18:39:49 UTC (rev 75894)
@@ -106,7 +106,7 @@
                 components[k] = d
             components = d
 
-        if components.get(name) == value:
+        if components.get(name) is value:
             return
         
         components[name] = value
@@ -155,7 +155,7 @@
         old = components.get(name)
         if old is None:
             return
-        if (value is not None) and (old != value):
+        if (value is not None) and (old is not value):
             return
 
         del components[name]
@@ -220,7 +220,7 @@
         if value is None:
             new = ()
         else:
-            new = tuple([v for v in old if v != value])
+            new = tuple([v for v in old if v is not value])
 
         if new == old:
             return

Modified: zope.interface/trunk/src/zope/interface/tests/test_adapter.py
===================================================================
--- zope.interface/trunk/src/zope/interface/tests/test_adapter.py	2007-05-22 18:28:27 UTC (rev 75893)
+++ zope.interface/trunk/src/zope/interface/tests/test_adapter.py	2007-05-22 18:39:49 UTC (rev 75894)
@@ -321,7 +321,29 @@
     'Y'
 """
 
+def test_register_objects_with_cmp():
+    """
+    The registry should never use == as that will tend to fail when
+    objects are picky about what they are compared with:
 
+    >>> class Picky:
+    ...     def __cmp__(self, other):
+    ...         raise TypeError("I\'m too picky for comparison!")
+    >>> class I(zope.interface.Interface):
+    ...     pass
+    >>> class I2(I, I):
+    ...     pass
+
+    >>> registry = AdapterRegistry()
+    >>> picky = Picky()
+    >>> registry.register([I2], IR0, '', picky)
+    >>> registry.unregister([I2], IR0, '', picky)
+
+    >>> registry.subscribe([I2], IR0, picky)
+    >>> registry.unsubscribe([I2], IR0, picky)
+
+    """
+
 def test_suite():
     from zope.testing import doctest, doctestunit
     return unittest.TestSuite((



More information about the Checkins mailing list