Skip to content

Commit 218dc00

Browse files
committed
Add a test
1 parent 8097826 commit 218dc00

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,22 @@ def testfunc(n):
17821782
self.assertNotIn("_GUARD_NOS_NULL", uops)
17831783
self.assertNotIn("_GUARD_CALLABLE_TYPE_1", uops)
17841784

1785+
def test_call_type_1_result_is_const(self):
1786+
def testfunc(n):
1787+
x = 0
1788+
for _ in range(n):
1789+
t = type(42)
1790+
if t is not None: # guard is removed
1791+
x += 1
1792+
return x
1793+
1794+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
1795+
self.assertEqual(res, TIER2_THRESHOLD)
1796+
self.assertIsNotNone(ex)
1797+
uops = get_opnames(ex)
1798+
self.assertIn("_CALL_TYPE_1", uops)
1799+
self.assertNotIn("_GUARD_IS_NOT_NONE_POP", uops)
1800+
17851801

17861802
def global_identity(x):
17871803
return x

0 commit comments

Comments
 (0)