Skip to content

Commit 0aaa3c7

Browse files
committed
allow comparison of builtin methods, fixes test_descr.methodwrapper minus its
implementation detail
1 parent d3f9072 commit 0aaa3c7

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

Lib/test/test_descr.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4199,7 +4199,10 @@ def methodwrapper():
41994199
verify(l.__add__ != l.__mul__)
42004200
verify(l.__add__.__name__ == '__add__')
42014201
verify(l.__add__.__self__ is l)
4202-
verify(l.__add__.__objclass__ is list)
4202+
if not is_jython:
4203+
# XXX: method-wrapper implementation detail, not all builtin
4204+
# instance methods have __objclass__ (e.g. l.append)
4205+
verify(l.__add__.__objclass__ is list)
42034206
vereq(l.__add__.__doc__, list.__add__.__doc__)
42044207
try:
42054208
hash(l.__add__)
@@ -4419,10 +4422,6 @@ def test_main():
44194422
# Lack __basicsize__: http://bugs.jython.org/issue1017
44204423
slotmultipleinheritance,
44214424

4422-
# Jython lacks CPython method-wrappers (though maybe this
4423-
# should pass anyway?)
4424-
methodwrapper,
4425-
44264425
# derived classes don't support coerce:
44274426
# http://bugs.jython.org/issue1060
44284427
notimplemented

src/org/python/core/PyBuiltinMethod.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,25 @@ public int hashCode() {
5050
int hashCode = self == null ? 0 : self.hashCode();
5151
return hashCode ^ getClass().hashCode();
5252
}
53+
54+
@Override
55+
public int __cmp__(PyObject other) {
56+
if (!(other instanceof PyBuiltinMethod)) {
57+
return -2;
58+
}
59+
PyBuiltinMethod otherMethod = (PyBuiltinMethod)other;
60+
if (self != otherMethod.self) {
61+
if (self == null) {
62+
return -1;
63+
} else if (otherMethod.self == null) {
64+
return 1;
65+
}
66+
return self._cmp(otherMethod.self);
67+
}
68+
if (getClass() == otherMethod.getClass()) {
69+
return 0;
70+
}
71+
int compareTo = info.getName().compareTo(otherMethod.info.getName());
72+
return compareTo < 0 ? -1 : compareTo > 0 ? 1 : 0;
73+
}
5374
}

0 commit comments

Comments
 (0)