From: <pj...@us...> - 2009-09-11 05:35:02
|
Revision: 6782 http://jython.svn.sourceforge.net/jython/?rev=6782&view=rev Author: pjenvey Date: 2009-09-11 05:34:56 +0000 (Fri, 11 Sep 2009) Log Message: ----------- o fix PyTuple/List.equals not trying rich comparison (_eq) to all other PyObjects like PyObject.equals does o no need to synchronize all of PyList.equals Modified Paths: -------------- trunk/jython/Lib/test/test_seq_jy.py trunk/jython/src/org/python/core/PyList.java trunk/jython/src/org/python/core/PyTuple.java Modified: trunk/jython/Lib/test/test_seq_jy.py =================================================================== --- trunk/jython/Lib/test/test_seq_jy.py 2009-09-11 05:22:00 UTC (rev 6781) +++ trunk/jython/Lib/test/test_seq_jy.py 2009-09-11 05:34:56 UTC (rev 6782) @@ -27,6 +27,13 @@ self.assertTrue(foo in seq1) self.assertFalse(eq_called) + def test_seq_equality(self): + for type2test in self.types2test: + class Foo(object): + def __eq__(self, other): + return True + self.assertTrue(type2test() in [Foo()]) + def test_seq_subclass_equality(self): # Various combinations of PyObject._eq, overriden Object.equals, # and cmp implementations Modified: trunk/jython/src/org/python/core/PyList.java =================================================================== --- trunk/jython/src/org/python/core/PyList.java 2009-09-11 05:22:00 UTC (rev 6781) +++ trunk/jython/src/org/python/core/PyList.java 2009-09-11 05:34:56 UTC (rev 6782) @@ -953,16 +953,21 @@ } @Override - public synchronized boolean equals(Object other) { + public boolean equals(Object other) { if (this == other) { return true; } - if (other instanceof PyList) { - return _eq((PyList)other).__nonzero__(); - } else if (other instanceof List && !(other instanceof PyTuple)) { - List otherList = (List)other; - return list.equals(otherList); + + if (other instanceof PyObject) { + synchronized (this) { + return _eq((PyObject)other).__nonzero__(); + } } + if (other instanceof List) { + synchronized (this) { + return list.equals(other); + } + } return false; } Modified: trunk/jython/src/org/python/core/PyTuple.java =================================================================== --- trunk/jython/src/org/python/core/PyTuple.java 2009-09-11 05:22:00 UTC (rev 6781) +++ trunk/jython/src/org/python/core/PyTuple.java 2009-09-11 05:34:56 UTC (rev 6782) @@ -476,9 +476,11 @@ if (this == other) { return true; } - if (other instanceof PyTuple) { - return _eq((PyTuple)other).__nonzero__(); - } else if (other instanceof List && !(other instanceof PyList)) { + + if (other instanceof PyObject) { + return _eq((PyObject)other).__nonzero__(); + } + if (other instanceof List) { return other.equals(this); } return false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |