From: <pj...@us...> - 2008-11-08 00:08:31
|
Revision: 5557 http://jython.svn.sourceforge.net/jython/?rev=5557&view=rev Author: pjenvey Date: 2008-11-08 00:08:20 +0000 (Sat, 08 Nov 2008) Log Message: ----------- rearrange the rich cmp methods so they can't call themselves fixes #1115 thanks Tom Mueller Modified Paths: -------------- trunk/jython/Lib/test/test_list_jy.py trunk/jython/src/org/python/core/PySequence.java Modified: trunk/jython/Lib/test/test_list_jy.py =================================================================== --- trunk/jython/Lib/test/test_list_jy.py 2008-11-07 08:25:32 UTC (rev 5556) +++ trunk/jython/Lib/test/test_list_jy.py 2008-11-08 00:08:20 UTC (rev 5557) @@ -1,17 +1,30 @@ import unittest import test.test_support -class ListTest(unittest.TestCase): - - def test_recursive_list_slices(self): - x = [1,2,3,4,5] - x[1:] = x +class ListTestCase(unittest.TestCase): - self.assertEquals(x, [1, 1, 2, 3, 4, 5], - "Recursive assignment to list slices failed") + def test_recursive_list_slices(self): + x = [1,2,3,4,5] + x[1:] = x + self.assertEquals(x, [1, 1, 2, 3, 4, 5], + "Recursive assignment to list slices failed") + def test_subclass_richcmp(self): + # http://bugs.jython.org/issue1115 + class Foo(list): + def __init__(self, dotstring): + list.__init__(self, map(int, dotstring.split("."))) + bar1 = Foo('1.2.3') + bar2 = Foo('1.2.4') + self.assert_(bar1 < bar2) + self.assert_(bar1 <= bar2) + self.assert_(bar2 > bar1) + self.assert_(bar2 >= bar1) + + def test_main(): - test.test_support.run_unittest(ListTest) + test.test_support.run_unittest(ListTestCase) + if __name__ == "__main__": - test_main() + test_main() Modified: trunk/jython/src/org/python/core/PySequence.java =================================================================== --- trunk/jython/src/org/python/core/PySequence.java 2008-11-07 08:25:32 UTC (rev 5556) +++ trunk/jython/src/org/python/core/PySequence.java 2008-11-08 00:08:20 UTC (rev 5557) @@ -136,6 +136,10 @@ } public synchronized PyObject __lt__(PyObject o) { + return seq___lt__(o); + } + + final synchronized PyObject seq___lt__(PyObject o) { if(!(getType() == o.getType()) && !(getType().isSubType(o.getType()))) { return null; } @@ -146,11 +150,11 @@ return __finditem__(i)._lt(o.__finditem__(i)); } - final synchronized PyObject seq___lt__(PyObject o) { - return __lt__(o); + public synchronized PyObject __le__(PyObject o) { + return seq___le__(o); } - public synchronized PyObject __le__(PyObject o) { + final synchronized PyObject seq___le__(PyObject o) { if(!(getType() == o.getType()) && !(getType().isSubType(o.getType()))) { return null; } @@ -161,11 +165,11 @@ return __finditem__(i)._le(o.__finditem__(i)); } - final synchronized PyObject seq___le__(PyObject o) { - return __le__(o); + public synchronized PyObject __gt__(PyObject o) { + return seq___gt__(o); } - public synchronized PyObject __gt__(PyObject o) { + final synchronized PyObject seq___gt__(PyObject o) { if(!(getType() == o.getType()) && !(getType().isSubType(o.getType()))) { return null; } @@ -175,11 +179,11 @@ return __finditem__(i)._gt(o.__finditem__(i)); } - final synchronized PyObject seq___gt__(PyObject o) { - return __gt__(o); + public synchronized PyObject __ge__(PyObject o) { + return seq___ge__(o); } - public synchronized PyObject __ge__(PyObject o) { + final synchronized PyObject seq___ge__(PyObject o) { if(!(getType() == o.getType()) && !(getType().isSubType(o.getType()))) { return null; } @@ -190,10 +194,6 @@ return __finditem__(i)._ge(o.__finditem__(i)); } - final synchronized PyObject seq___ge__(PyObject o) { - return __ge__(o); - } - // Return value >= 0 is the index where the sequences differs. // -1: reached the end of o1 without a difference // -2: reached the end of both seqeunces without a difference This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |