[Checkins] SVN: zope.interface/branches/regebro-python3/ Prepare for python3 compatibility: comparing None to None is not allowed anymore in py3, so we can't expect a list with multiple Nones (and interfaces) to be sortable *at all*.

Wolfgang Schnerring wosc at wosc.de
Sat Sep 12 10:37:44 EDT 2009


Log message for revision 103869:
  Prepare for python3 compatibility: comparing None to None is not allowed anymore in py3, so we can't expect a list with multiple Nones (and interfaces) to be sortable *at all*.
  
  Thus, we do not support using None instead of zope.interface.Interface anymore.
  

Changed:
  U   zope.interface/branches/regebro-python3/CHANGES.txt
  U   zope.interface/branches/regebro-python3/src/zope/interface/interface.py
  U   zope.interface/branches/regebro-python3/src/zope/interface/tests/test_sorting.py

-=-
Modified: zope.interface/branches/regebro-python3/CHANGES.txt
===================================================================
--- zope.interface/branches/regebro-python3/CHANGES.txt	2009-09-12 14:34:05 UTC (rev 103868)
+++ zope.interface/branches/regebro-python3/CHANGES.txt	2009-09-12 14:37:44 UTC (rev 103869)
@@ -2,10 +2,11 @@
 *******
 
 ==================
-3.5.3 (unreleased)
+3.6.0 (unreleased)
 ==================
 
-...
+- None is now allowed as a placeholder for zope.interface.Interface anymore,
+  in preparation for python3 compatibility.
 
 
 ==================

Modified: zope.interface/branches/regebro-python3/src/zope/interface/interface.py
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/interface.py	2009-09-12 14:34:05 UTC (rev 103868)
+++ zope.interface/branches/regebro-python3/src/zope/interface/interface.py	2009-09-12 14:37:44 UTC (rev 103869)
@@ -640,7 +640,7 @@
     def __reduce__(self):
         return self.__name__
 
-    def __cmp(self, o1, o2):
+    def __cmp(self, other):
         # Yes, I did mean to name this __cmp, rather than __cmp__.
         # It is a private method used by __lt__ and __gt__.
         # I don't want to override __eq__ because I want the default
@@ -657,33 +657,27 @@
 
         For now, sort on interface and module name.
 
-        None is treated as a pseudo interface that implies the loosest
-        contact possible, no contract. For that reason, all interfaces
-        sort before None.
-
         """
-        if o1 == o2:
+        if self == other:
             return 0
 
-        if o1 is None:
-            return 1
-        if o2 is None:
-            return -1
+        if not isinstance(other, type(self)):
+            raise TypeError('unorderable types: %s, %s' % self, other)
 
-        n1 = (getattr(o1, '__name__', ''),
-              getattr(getattr(o1,  '__module__', None), '__name__', ''))
-        n2 = (getattr(o2, '__name__', ''),
-              getattr(getattr(o2,  '__module__', None), '__name__', ''))
+        n1 = (getattr(self, '__name__', ''),
+              getattr(getattr(self,  '__module__', None), '__name__', ''))
+        n2 = (getattr(other, '__name__', ''),
+              getattr(getattr(other,  '__module__', None), '__name__', ''))
 
         return (n1 > n2) - (n1 < n2)
 
     def __lt__(self, other):
-        c = self.__cmp(self, other)
+        c = self.__cmp(other)
         #print '<', self, other, c < 0, c
         return c < 0
 
     def __gt__(self, other):
-        c = self.__cmp(self, other)
+        c = self.__cmp(other)
         #print '>', self, other, c > 0, c
         return c > 0
 

Modified: zope.interface/branches/regebro-python3/src/zope/interface/tests/test_sorting.py
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/tests/test_sorting.py	2009-09-12 14:34:05 UTC (rev 103868)
+++ zope.interface/branches/regebro-python3/src/zope/interface/tests/test_sorting.py	2009-09-12 14:37:44 UTC (rev 103869)
@@ -35,10 +35,9 @@
         l.sort()
         self.assertEqual(l, [I1, I2, I3, I4, I5, I6])
 
-    def test_w_None(self):
-        l = [I1, None, I3, I5, None, I6, I4, I2]
-        l.sort()
-        self.assertEqual(l, [I1, I2, I3, I4, I5, I6, None, None])
+    def test_none_not_allowed_anymore(self):
+        l = [I1, I3, I5, None, I6, I4, I2]
+        self.assertRaises(TypeError, l.sort)
 
 def test_suite():
     return TestSuite((



More information about the checkins mailing list