Index: src/org/python/modules/sets/PyImmutableSet.java =================================================================== --- src/org/python/modules/sets/PyImmutableSet.java (revision 4402) +++ src/org/python/modules/sets/PyImmutableSet.java (working copy) @@ -1,6 +1,7 @@ package org.python.modules.sets; import org.python.core.PyBuiltinFunction; +import org.python.core.PyInteger; import org.python.core.PyObject; import org.python.core.PyType; import org.python.expose.ExposedMethod; @@ -41,6 +42,11 @@ } @ExposedMethod(type = MethodType.BINARY) + final PyObject ImmutableSet___cmp__(PyObject o) { + return new PyInteger(baseset___cmp__(o)); + } + + @ExposedMethod(type = MethodType.BINARY) final PyObject ImmutableSet___ne__(PyObject o) { return baseset___ne__(o); } Index: src/org/python/modules/sets/PySet.java =================================================================== --- src/org/python/modules/sets/PySet.java (revision 4402) +++ src/org/python/modules/sets/PySet.java (working copy) @@ -5,6 +5,7 @@ import org.python.core.Py; import org.python.core.PyBuiltinFunction; import org.python.core.PyException; +import org.python.core.PyInteger; import org.python.core.PyObject; import org.python.core.PyType; import org.python.expose.ExposedMethod; @@ -45,6 +46,11 @@ } @ExposedMethod(type = MethodType.BINARY) + final PyObject Set___cmp__(PyObject o) { + return new PyInteger(baseset___cmp__(o)); + } + + @ExposedMethod(type = MethodType.BINARY) final PyObject Set___ne__(PyObject o) { return baseset___ne__(o); } Index: src/org/python/modules/sets/BaseSet.java =================================================================== --- src/org/python/modules/sets/BaseSet.java (revision 4402) +++ src/org/python/modules/sets/BaseSet.java (working copy) @@ -55,7 +55,6 @@ * @throws PyIgnoreMethodTag Ignore. */ protected void _update(PyObject data) throws PyIgnoreMethodTag { - if(data instanceof BaseSet) { // Skip the iteration if both are sets this._set.addAll(((BaseSet)data)._set); @@ -134,11 +133,10 @@ } final PyObject baseset_difference(PyObject other) { - BaseSet iterable = (other instanceof BaseSet) ? (BaseSet) other : new PySet(other); - Set set = iterable._set; + BaseSet bs = (other instanceof BaseSet) ? (BaseSet) other : new PySet(other); + Set set = bs._set; BaseSet o = (BaseSet) this.getType().__call__(); - for (Iterator i = this._set.iterator(); i.hasNext();) { - Object p = i.next(); + for (Object p : this._set) { if (!set.contains(p)) { o._set.add(p); } @@ -172,16 +170,14 @@ } public PyObject baseset_symmetric_difference(PyObject other) { - BaseSet iterable = (other instanceof BaseSet) ? (BaseSet) other : new PySet(other); + BaseSet bs = (other instanceof BaseSet) ? (BaseSet) other : new PySet(other); BaseSet o = (BaseSet) this.getType().__call__(); - for (Iterator i = this._set.iterator(); i.hasNext();) { - Object p = i.next(); - if (!iterable._set.contains(p)) { + for (Object p : this._set) { + if (!bs._set.contains(p)) { o._set.add(p); } } - for (Iterator i = iterable._set.iterator(); i.hasNext();) { - Object p = i.next(); + for (Object p : bs._set) { if (!this._set.contains(p)) { o._set.add(p); } @@ -244,14 +240,21 @@ return this._set.contains(other); } + public int __cmp__(PyObject other) { + return baseset___cmp__(other); + } + + final int baseset___cmp__(PyObject other) { + throw Py.TypeError("cannot compare sets using cmp()"); + } + public PyObject __eq__(PyObject other) { return baseset___eq__(other); } final PyObject baseset___eq__(PyObject other) { - if(other instanceof BaseSet) { - BaseSet bs = this._binary_sanity_check(other); - return Py.newBoolean(this._set.equals(bs._set)); + if (other instanceof BaseSet) { + return Py.newBoolean(this._set.equals(((BaseSet)other)._set)); } return Py.False; } @@ -262,8 +265,7 @@ final PyObject baseset___ne__(PyObject other) { if(other instanceof BaseSet) { - BaseSet bs = this._binary_sanity_check(other); - return Py.newBoolean(!this._set.equals(bs._set)); + return Py.newBoolean(!this._set.equals(((BaseSet)other)._set)); } return Py.True; } @@ -273,6 +275,7 @@ } final PyObject baseset___le__(PyObject other) { + BaseSet bs = this._binary_sanity_check(other); return this.baseset_issubset(other); } @@ -281,6 +284,7 @@ } final PyObject baseset___ge__(PyObject other) { + BaseSet bs = this._binary_sanity_check(other); return this.baseset_issuperset(other); } @@ -330,8 +334,8 @@ PyObject deepcopy = copy.__getattr__("deepcopy"); BaseSet result = (BaseSet) this.getType().__call__(); memo.__setitem__(Py.newInteger(Py.id(this)), result); - for (Iterator iterator = this._set.iterator(); iterator.hasNext();) { - result._set.add(deepcopy.__call__(Py.java2py(iterator.next()), memo)); + for (Object p : this._set) { + result._set.add(deepcopy.__call__(Py.java2py(p), memo)); } return result; } @@ -381,12 +385,12 @@ } public PyObject baseset_issubset(PyObject other) { - BaseSet bs = this._binary_sanity_check(other); + BaseSet bs = (other instanceof BaseSet) ? (BaseSet) other : new PySet(other); if (this.__len__() > bs.__len__()) { return Py.False; } - for (Iterator iterator = this._set.iterator(); iterator.hasNext();) { - if (!bs._set.contains(iterator.next())) { + for (Object p : this._set) { + if (!bs._set.contains(p)) { return Py.False; } } @@ -394,12 +398,12 @@ } public PyObject baseset_issuperset(PyObject other) { - BaseSet bs = this._binary_sanity_check(other); + BaseSet bs = (other instanceof BaseSet) ? (BaseSet) other : new PySet(other); if (this.__len__() < bs.__len__()) { return Py.False; } - for (Iterator iterator = bs._set.iterator(); iterator.hasNext();) { - if (!this._set.contains(iterator.next())) { + for (Object p : bs._set) { + if (!this._set.contains(p)) { return Py.False; } }