summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Fulton <jim@zope.com>2007-05-22 18:39:49 +0000
committerJim Fulton <jim@zope.com>2007-05-22 18:39:49 +0000
commite10e89d7bf795762220759f2fba23ac2f2cea28d (patch)
treed1be14fb2d9e1c89d214f45e385bbf30b9b7522e /src
parent4fbc5e8af21b6e293b1f474cf554ea5cc4b8d880 (diff)
downloadzope-interface-e10e89d7bf795762220759f2fba23ac2f2cea28d.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/zope/interface/adapter.py6
-rw-r--r--src/zope/interface/tests/test_adapter.py22
2 files changed, 25 insertions, 3 deletions
diff --git a/src/zope/interface/adapter.py b/src/zope/interface/adapter.py
index 3794b0e..a8dd335 100644
--- a/src/zope/interface/adapter.py
+++ b/src/zope/interface/adapter.py
@@ -106,7 +106,7 @@ class BaseAdapterRegistry(object):
components[k] = d
components = d
- if components.get(name) == value:
+ if components.get(name) is value:
return
components[name] = value
@@ -155,7 +155,7 @@ class BaseAdapterRegistry(object):
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 @@ class BaseAdapterRegistry(object):
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
diff --git a/src/zope/interface/tests/test_adapter.py b/src/zope/interface/tests/test_adapter.py
index cc8ebd2..33fb5e1 100644
--- a/src/zope/interface/tests/test_adapter.py
+++ b/src/zope/interface/tests/test_adapter.py
@@ -321,6 +321,28 @@ There was a bug that caused problems if a spec had multiple bases:
'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