[pypy-commit] pypy guard-compatible: do the same trick we also do for object.__getattribute__:

cfbolz pypy.commits at gmail.com
Wed Mar 30 09:46:50 EDT 2016


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: guard-compatible
Changeset: r83436:a42555cba817
Date: 2016-03-30 14:05 +0200
http://bitbucket.org/pypy/pypy/changeset/a42555cba817/

Log:	do the same trick we also do for object.__getattribute__: if the
	__instancecheck__ method is not overridden, don't go via the method
	at all.

diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -58,6 +58,13 @@
     return w_iter
 tuple_iter._annspecialcase_ = 'specialize:memo'
 
+def type_instancecheck(space):
+    "Utility that returns the app-level descriptor type.__instancecheck__."
+    w_src, w_instancecheck = space.lookup_in_type_where(space.w_type,
+                                               '__instancecheck__')
+    return w_instancecheck
+type_instancecheck._annspecialcase_ = 'specialize:memo'
+
 def raiseattrerror(space, w_obj, name, w_descr=None):
     if w_descr is None:
         raise oefmt(space.w_AttributeError,
@@ -524,12 +531,12 @@
         if not jit.we_are_jitted() and space.type(w_inst) is w_type:
             return space.w_True # fast path copied from cpython
         w_check = space.lookup(w_type, "__instancecheck__")
-        if w_check is not None:
+        if w_check is None or w_check is type_instancecheck(space):
+            return space.isinstance(w_inst, w_type)
+        else:
             if space.type(w_inst) is w_type:
                 return space.w_True # fast path copied from cpython
             return space.get_and_call_function(w_check, w_type, w_inst)
-        else:
-            return space.isinstance(w_inst, w_type)
 
 
 # helpers


More information about the pypy-commit mailing list