File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -2053,6 +2053,31 @@ def testfunc(n):
20532053 self .assertNotIn ("_TO_BOOL_BOOL" , uops )
20542054 self .assertIn ("_GUARD_IS_TRUE_POP" , uops )
20552055
2056+ def test_call_isinstance_metaclass (self ):
2057+ class EvenNumberMeta (type ):
2058+ def __instancecheck__ (self , number ):
2059+ return number % 2 == 0
2060+
2061+ class EvenNumber (metaclass = EvenNumberMeta ):
2062+ pass
2063+
2064+ def testfunc (n ):
2065+ x = 0
2066+ for _ in range (n ):
2067+ # Only narrowed to bool
2068+ y = isinstance (42 , EvenNumber )
2069+ if y :
2070+ x += 1
2071+ return x
2072+
2073+ res , ex = self ._run_with_optimizer (testfunc , TIER2_THRESHOLD )
2074+ self .assertEqual (res , TIER2_THRESHOLD )
2075+ self .assertIsNotNone (ex )
2076+ uops = get_opnames (ex )
2077+ self .assertIn ("_CALL_ISINSTANCE" , uops )
2078+ self .assertNotIn ("_TO_BOOL_BOOL" , uops )
2079+ self .assertIn ("_GUARD_IS_TRUE_POP" , uops )
2080+
20562081
20572082def global_identity (x ):
20582083 return x
You can’t perform that action at this time.
0 commit comments