[Checkins] SVN: zope.interface/branches/regebro-python3/ The non-sortability of None is only an issue if you have two Nones in the list. It may become a problem in zope.component, but then we handle it there. Using None is not unusual, and removing that option will break lots of code.
Lennart Regebro
regebro at gmail.com
Sat Dec 5 03:02:12 EST 2009
Log message for revision 106212:
The non-sortability of None is only an issue if you have two Nones in the list. It may become a problem in zope.component, but then we handle it there. Using None is not unusual, and removing that option will break lots of code.
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-12-05 07:47:32 UTC (rev 106211)
+++ zope.interface/branches/regebro-python3/CHANGES.txt 2009-12-05 08:02:12 UTC (rev 106212)
@@ -2,11 +2,10 @@
*******
==================
-3.6.0 (unreleased)
+3.5.3 (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-12-05 07:47:32 UTC (rev 106211)
+++ zope.interface/branches/regebro-python3/src/zope/interface/interface.py 2009-12-05 08:02:12 UTC (rev 106212)
@@ -640,7 +640,7 @@
def __reduce__(self):
return self.__name__
- def __cmp(self, other):
+ def __cmp(self, o1, o2):
# 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,27 +657,33 @@
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 self == other:
+ if o1 == o2:
return 0
- if not isinstance(other, type(self)):
- raise TypeError('unorderable types: %s, %s' % self, other)
+ if o1 is None:
+ return 1
+ if o2 is None:
+ return -1
- n1 = (getattr(self, '__name__', ''),
- getattr(getattr(self, '__module__', None), '__name__', ''))
- n2 = (getattr(other, '__name__', ''),
- getattr(getattr(other, '__module__', None), '__name__', ''))
+ n1 = (getattr(o1, '__name__', ''),
+ getattr(getattr(o1, '__module__', None), '__name__', ''))
+ n2 = (getattr(o2, '__name__', ''),
+ getattr(getattr(o2, '__module__', None), '__name__', ''))
return (n1 > n2) - (n1 < n2)
def __lt__(self, other):
- c = self.__cmp(other)
+ c = self.__cmp(self, other)
#print '<', self, other, c < 0, c
return c < 0
def __gt__(self, other):
- c = self.__cmp(other)
+ c = self.__cmp(self, 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-12-05 07:47:32 UTC (rev 106211)
+++ zope.interface/branches/regebro-python3/src/zope/interface/tests/test_sorting.py 2009-12-05 08:02:12 UTC (rev 106212)
@@ -35,9 +35,10 @@
l.sort()
self.assertEqual(l, [I1, I2, I3, I4, I5, I6])
- def test_none_not_allowed_anymore(self):
- l = [I1, I3, I5, None, I6, I4, I2]
- self.assertRaises(TypeError, l.sort)
+ def test_w_None(self):
+ l = [I1, None, I3, I5, I6, I4, I2]
+ l.sort()
+ self.assertEqual(l, [I1, I2, I3, I4, I5, I6, None])
def test_suite():
return TestSuite((
More information about the checkins
mailing list