[Checkins] SVN: zope.interface/branches/3.6/ Correctly compare interfaces from different modules but with the same names.

Tres Seaver tseaver at palladion.com
Sat Aug 13 13:43:48 EDT 2011


Log message for revision 122572:
  Correctly compare interfaces  from different modules but with the same names.
  
  Fixes LP #570942.
  
  N.B.: This is a less intrusive / destabilizing fix than the one applied in
  3.6.3:  we only fix the underlying cmp-alike function, rather than adding
  the other "rich comparison" functions.
  

Changed:
  U   zope.interface/branches/3.6/CHANGES.txt
  U   zope.interface/branches/3.6/src/zope/interface/interface.py
  A   zope.interface/branches/3.6/src/zope/interface/tests/ifoo_other.py
  U   zope.interface/branches/3.6/src/zope/interface/tests/test_interface.py

-=-
Modified: zope.interface/branches/3.6/CHANGES.txt
===================================================================
--- zope.interface/branches/3.6/CHANGES.txt	2011-08-13 17:33:16 UTC (rev 122571)
+++ zope.interface/branches/3.6/CHANGES.txt	2011-08-13 17:43:47 UTC (rev 122572)
@@ -4,6 +4,13 @@
 3.6.6 (unreleased)
 ------------------
 
+- LP #570942:  Now correctly compare interfaces  from different modules but
+  with the same names.
+  
+  N.B.: This is a less intrusive / destabilizing fix than the one applied in
+  3.6.3:  we only fix the underlying cmp-alike function, rather than adding
+  the other "rich comparison" functions.
+
 - Revert to software as released with 3.6.1 for "stable" 3.6 release branch.
 
 3.6.5 (2011-08-11)

Modified: zope.interface/branches/3.6/src/zope/interface/interface.py
===================================================================
--- zope.interface/branches/3.6/src/zope/interface/interface.py	2011-08-13 17:33:16 UTC (rev 122571)
+++ zope.interface/branches/3.6/src/zope/interface/interface.py	2011-08-13 17:43:47 UTC (rev 122572)
@@ -678,10 +678,8 @@
         if o2 is None:
             return -1
 
-        n1 = (getattr(o1, '__name__', ''),
-              getattr(getattr(o1,  '__module__', None), '__name__', ''))
-        n2 = (getattr(o2, '__name__', ''),
-              getattr(getattr(o2,  '__module__', None), '__name__', ''))
+        n1 = (getattr(o1, '__name__', ''), getattr(o1,  '__module__', None))
+        n2 = (getattr(o2, '__name__', ''), getattr(o2,  '__module__', None))
 
         return (n1 > n2) - (n1 < n2)
 

Copied: zope.interface/branches/3.6/src/zope/interface/tests/ifoo_other.py (from rev 122570, zope.interface/trunk/src/zope/interface/tests/ifoo_other.py)
===================================================================
--- zope.interface/branches/3.6/src/zope/interface/tests/ifoo_other.py	                        (rev 0)
+++ zope.interface/branches/3.6/src/zope/interface/tests/ifoo_other.py	2011-08-13 17:43:47 UTC (rev 122572)
@@ -0,0 +1,26 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""IFoo test module
+"""
+from zope.interface import Interface
+
+class IFoo(Interface):
+    """
+        Dummy interface for unit tests.
+    """
+
+    def bar(baz):
+        """
+            Just a note.
+        """

Modified: zope.interface/branches/3.6/src/zope/interface/tests/test_interface.py
===================================================================
--- zope.interface/branches/3.6/src/zope/interface/tests/test_interface.py	2011-08-13 17:33:16 UTC (rev 122571)
+++ zope.interface/branches/3.6/src/zope/interface/tests/test_interface.py	2011-08-13 17:43:47 UTC (rev 122572)
@@ -348,8 +348,20 @@
         # Old style classes don't have a '__class__' attribute
         self.failUnlessRaises(AttributeError, I.providedBy, Bad)
 
+    def test_comparison_with_same_named_instance_in_other_module(self):
+        # See LP #570942
+        from zope.interface.tests.ifoo import IFoo as IFoo1
+        from zope.interface.tests.ifoo_other import IFoo as IFoo2
 
+        self.failUnless(IFoo1 < IFoo2)
+        self.failUnless(IFoo1 <= IFoo2)
+        self.failIf(IFoo1 == IFoo2)
+        self.failUnless(IFoo1 != IFoo2)
+        self.failIf(IFoo1 >= IFoo2)
+        self.failIf(IFoo1 > IFoo2)
 
+
+
 if sys.version_info >= (2, 4):
 
     def test_invariant_as_decorator():



More information about the checkins mailing list