[Jython-checkins] jython: Implemented rich comparison methods for PyType (fixes #1886)

alex.gronholm jython-checkins at python.org
Sun Oct 28 14:08:54 CET 2012


http://hg.python.org/jython/rev/70014cb9f0a9
changeset:   6877:70014cb9f0a9
user:        Alex Grönholm <alex.gronholm at nextday.fi>
date:        Sun Oct 28 06:00:51 2012 +0200
summary:
  Implemented rich comparison methods for PyType (fixes #1886)

files:
  src/org/python/core/PyType.java |  43 +++++++++++++++++++++
  1 files changed, 43 insertions(+), 0 deletions(-)


diff --git a/src/org/python/core/PyType.java b/src/org/python/core/PyType.java
--- a/src/org/python/core/PyType.java
+++ b/src/org/python/core/PyType.java
@@ -18,6 +18,7 @@
 import org.python.expose.ExposedNew;
 import org.python.expose.ExposedSet;
 import org.python.expose.ExposedType;
+import org.python.expose.MethodType;
 import org.python.expose.TypeBuilder;
 import org.python.modules._weakref.WeakrefModule;
 import org.python.util.Generic;
@@ -674,6 +675,48 @@
         bases = cleanedBases.toArray(new PyObject[cleanedBases.size()]);
     }
 
+    @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.type___eq___doc)
+    public PyObject type___eq__(PyObject other) {
+        if (!(other instanceof PyType))
+            return null;
+        return equals(other) ? Py.True : Py.False;
+    }
+
+    @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.type___ne___doc)
+    public PyObject type___ne__(PyObject other) {
+        if (!(other instanceof PyType))
+            return null;
+        return equals(other) ? Py.False : Py.True;
+    }
+
+    @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.type___le___doc)
+    public PyObject type___le__(PyObject other) {
+        if (!(other instanceof PyType))
+            return null;
+        return equals(other) ? Py.True : Py.False;
+    }
+
+    @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.type___lt___doc)
+    public PyObject type___lt__(PyObject other) {
+        if (!(other instanceof PyType))
+            return null;
+        return equals(other) ? Py.True : Py.False;
+    }
+
+    @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.type___ge___doc)
+    public PyObject type___ge__(PyObject other) {
+        if (!(other instanceof PyType))
+            return null;
+        return equals(other) ? Py.True : Py.False;
+    }
+
+    @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.type___gt___doc)
+    public PyObject type___gt__(PyObject other) {
+        if (!(other instanceof PyType))
+            return null;
+        return equals(other) ? Py.True : Py.False;
+    }
+    
     @ExposedGet(name = "__base__")
     public PyObject getBase() {
         if (base == null)

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list