From: <pj...@us...> - 2009-05-03 06:09:33
|
Revision: 6287 http://jython.svn.sourceforge.net/jython/?rev=6287&view=rev Author: pjenvey Date: 2009-05-03 06:09:20 +0000 (Sun, 03 May 2009) Log Message: ----------- match CPython's object.c::try_rich_compare: don't bother swapping the binop if the first op returned NotImplemented (null). _eq and friends already do this Modified Paths: -------------- trunk/jython/Lib/test/test_cmp_jy.py trunk/jython/src/org/python/core/PyObject.java Modified: trunk/jython/Lib/test/test_cmp_jy.py =================================================================== --- trunk/jython/Lib/test/test_cmp_jy.py 2009-05-02 07:55:28 UTC (rev 6286) +++ trunk/jython/Lib/test/test_cmp_jy.py 2009-05-03 06:09:20 UTC (rev 6287) @@ -56,6 +56,13 @@ # object.c:default_3way_compare, and gets 1 here. we don't care self.assert_(cmp(100, baz) in (-1, 1)) + def test_cmp_stops_short(self): + class Foo(object): + __eq__ = lambda self, other: False + class Bar(object): + __eq__ = lambda self, other: True + self.assertEqual(cmp(Foo(), Bar()), 1) + def test_main(): test_support.run_unittest( UnicodeDerivedCmp, Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2009-05-02 07:55:28 UTC (rev 6286) +++ trunk/jython/src/org/python/core/PyObject.java 2009-05-03 06:09:20 UTC (rev 6287) @@ -1260,27 +1260,30 @@ return 0; } - PyObject r; - r = __eq__(o); - if (r != null && r.__nonzero__()) + PyObject result; + result = __eq__(o); + if (result == null) { + result = o.__eq__(this); + } + if (result != null && result.__nonzero__()) { return 0; - r = o.__eq__(this); - if (r != null && r.__nonzero__()) - return 0; + } - r = __lt__(o); - if (r != null && r.__nonzero__()) + result = __lt__(o); + if (result == null) { + result = o.__gt__(this); + } + if (result != null && result.__nonzero__()) { return -1; - r = o.__gt__(this); - if (r != null && r.__nonzero__()) - return -1; + } - r = __gt__(o); - if (r != null && r.__nonzero__()) + result = __gt__(o); + if (result == null) { + result = o.__lt__(this); + } + if (result != null && result.__nonzero__()) { return 1; - r = o.__lt__(this); - if (r != null && r.__nonzero__()) - return 1; + } return _cmp_unsafe(o); } finally { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |