From: <pj...@us...> - 2009-04-06 02:35:32
|
Revision: 6173 http://jython.svn.sourceforge.net/jython/?rev=6173&view=rev Author: pjenvey Date: 2009-04-06 02:35:31 +0000 (Mon, 06 Apr 2009) Log Message: ----------- allow comparison of builtin methods, fixes test_descr.methodwrapper minus its implementation detail Modified Paths: -------------- trunk/jython/Lib/test/test_descr.py trunk/jython/src/org/python/core/PyBuiltinMethod.java Modified: trunk/jython/Lib/test/test_descr.py =================================================================== --- trunk/jython/Lib/test/test_descr.py 2009-04-06 01:38:32 UTC (rev 6172) +++ trunk/jython/Lib/test/test_descr.py 2009-04-06 02:35:31 UTC (rev 6173) @@ -4199,7 +4199,10 @@ verify(l.__add__ != l.__mul__) verify(l.__add__.__name__ == '__add__') verify(l.__add__.__self__ is l) - verify(l.__add__.__objclass__ is list) + if not is_jython: + # XXX: method-wrapper implementation detail, not all builtin + # instance methods have __objclass__ (e.g. l.append) + verify(l.__add__.__objclass__ is list) vereq(l.__add__.__doc__, list.__add__.__doc__) try: hash(l.__add__) @@ -4419,10 +4422,6 @@ # Lack __basicsize__: http://bugs.jython.org/issue1017 slotmultipleinheritance, - # Jython lacks CPython method-wrappers (though maybe this - # should pass anyway?) - methodwrapper, - # derived classes don't support coerce: # http://bugs.jython.org/issue1060 notimplemented Modified: trunk/jython/src/org/python/core/PyBuiltinMethod.java =================================================================== --- trunk/jython/src/org/python/core/PyBuiltinMethod.java 2009-04-06 01:38:32 UTC (rev 6172) +++ trunk/jython/src/org/python/core/PyBuiltinMethod.java 2009-04-06 02:35:31 UTC (rev 6173) @@ -50,4 +50,25 @@ int hashCode = self == null ? 0 : self.hashCode(); return hashCode ^ getClass().hashCode(); } + + @Override + public int __cmp__(PyObject other) { + if (!(other instanceof PyBuiltinMethod)) { + return -2; + } + PyBuiltinMethod otherMethod = (PyBuiltinMethod)other; + if (self != otherMethod.self) { + if (self == null) { + return -1; + } else if (otherMethod.self == null) { + return 1; + } + return self._cmp(otherMethod.self); + } + if (getClass() == otherMethod.getClass()) { + return 0; + } + int compareTo = info.getName().compareTo(otherMethod.info.getName()); + return compareTo < 0 ? -1 : compareTo > 0 ? 1 : 0; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |