Amaury Forgeot d'Arc committed 24cea2c

Respect __subclasscheck__ when rebinding a method to a more specific class.
This change is needed to make OrderedDict() work at all,
but it may have unexpected performance impact.

Comments (0)

Files changed (2)


             # only allow binding to a more specific class than before
             if (w_cls is not None and
                 not space.is_w(w_cls, space.w_None) and
-                not space.abstract_issubclass_w(w_cls, self.w_class)):
+                not space.is_true(
+                    space.issubtype_allow_override(w_cls, self.w_class))):
                 return space.wrap(self)    # subclass test failed
                 return descr_function_get(space, self.w_function, w_obj, w_cls)


         assert issubclass(B, B)
         assert issubclass(23, B)
+    def test_issubclass_and_method(self):
+        class Meta(type):
+            def __subclasscheck__(cls, sub):
+                if sub is Dict:
+                    return True
+        class A:
+            __metaclass__ = Meta
+            def method(self):
+                return 42
+        class Dict:
+            method = A.method
+        assert Dict().method() == 42
     def test_truth_of_long(self):
         class X(object):
             def __len__(self): return 1L