Author: Maciej Fijalkowski <[email protected]>
Branch: 
Changeset: r78637:7ebfda5c3881
Date: 2015-07-23 15:45 +0200
http://bitbucket.org/pypy/pypy/changeset/7ebfda5c3881/

Log:    (fijal, arigo) add a fast-path straight from cpython

diff --git a/pypy/module/__builtin__/test/test_abstractinst.py 
b/pypy/module/__builtin__/test/test_abstractinst.py
--- a/pypy/module/__builtin__/test/test_abstractinst.py
+++ b/pypy/module/__builtin__/test/test_abstractinst.py
@@ -202,3 +202,18 @@
             __subclass__ = set([int])
         assert issubclass(int, Integer)
         assert issubclass(int, (Integer,))
+
+    def test_dont_call_instancecheck_fast_path(self):
+        called = []
+        
+        class M(type):
+            def __instancecheck__(self, obj):
+                saddsadsa
+                called.append("called")
+
+        class C:
+            __metaclass__ = M
+
+        c = C()
+        assert isinstance(c, C)
+        assert not called
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -521,6 +521,8 @@
         return space.get_and_call_function(w_check, w_type, w_sub)
 
     def isinstance_allow_override(space, w_inst, w_type):
+        if 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:
             return space.get_and_call_function(w_check, w_type, w_inst)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to