Commits

Alex Grönholm  committed 70014cb

Implemented rich comparison methods for PyType (fixes #1886)

  • Participants
  • Parent commits 3a2007c

Comments (0)

Files changed (1)

File src/org/python/core/PyType.java

 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;
         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)