[Jython-checkins] jython: Fixes #2515 together with previous commit. Py.dispatchToChecker didn't consider

stefan.richthofer jython-checkins at python.org
Mon Jan 9 04:26:39 EST 2017


https://hg.python.org/jython/rev/57d5d84099db
changeset:   7995:57d5d84099db
user:        Stefan Richthofer <stefan.richthofer at gmx.de>
date:        Mon Jan 09 10:26:28 2017 +0100
summary:
  Fixes #2515 together with previous commit. Py.dispatchToChecker didn't consider the metaclass for __instancecheck__ and __subclasscheck__, but according to https://docs.python.org/2/reference/datamodel.html#customizing-instance-and-subclass-checks these methods must be defined in a metaclass only. Also see http://bugs.jython.org/issue2515 for details.

files:
  src/org/python/core/Py.java |  12 +++++++-----
  1 files changed, 7 insertions(+), 5 deletions(-)


diff --git a/src/org/python/core/Py.java b/src/org/python/core/Py.java
--- a/src/org/python/core/Py.java
+++ b/src/org/python/core/Py.java
@@ -2259,18 +2259,20 @@
      * checker
      */
     private static PyObject dispatchToChecker(PyObject checkerArg, PyObject cls,
-                                              String checkerName) {
+            String checkerName) {
         //Ignore old style classes.
         if (cls instanceof PyClass) {
             return null;
         }
-
-        PyObject checker = cls.__findattr__(checkerName);
+        PyObject meta = cls.__findattr__("__metaclass__");
+        if (meta == null) {
+            return null;
+        }
+        PyObject checker = meta.__findattr__(checkerName);
         if (checker == null) {
             return null;
         }
-
-        return checker.__call__(checkerArg);
+        return checker.__call__(cls, checkerArg);
     }
 
     /**

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


More information about the Jython-checkins mailing list