[Jython-checkins] jython: Added __instancecheck__ and __subclasscheck__ methods to type, like they are in

stefan.richthofer jython-checkins at python.org
Mon Jan 9 12:00:25 EST 2017


https://hg.python.org/jython/rev/0c4573848c75
changeset:   7998:0c4573848c75
user:        Stefan Richthofer <stefan.richthofer at gmx.de>
date:        Mon Jan 09 18:00:10 2017 +0100
summary:
  Added __instancecheck__ and __subclasscheck__ methods to type, like they are in CPython 2.7.

files:
  src/org/python/core/PyType.java |  17 +++++++++++++++++
  1 files changed, 17 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
@@ -928,6 +928,23 @@
         return result;
     }
 
+    @ExposedMethod(doc = BuiltinDocs.type___subclasscheck___doc)
+    public synchronized final boolean type___subclasscheck__(PyObject inst) {
+        return Py.isSubClass(inst, this);
+    }
+
+    @ExposedMethod(doc = BuiltinDocs.type___instancecheck___doc)
+    public synchronized final boolean type___instancecheck__(PyObject inst) {
+        /* We cannot directly call Py.isInstance(inst, this), because that
+         * would yield endless recursion. So we inline the essential parts
+         * from there, excluding checker-delegation and PyTuple special case.
+         */
+        if (inst.getType() == this) {
+            return true;
+        }
+        return Py.recursiveIsInstance(inst, this);
+    }
+
     /**
      * Returns the Java Class that this type inherits from, or null if this type is Python-only.
      */

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


More information about the Jython-checkins mailing list