Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Prev Previous commit
Next Next commit
Add a test
  • Loading branch information
tomasr8 committed Apr 14, 2025
commit 218dc00b38b69e6f614a037c7a01c756b426baf9
16 changes: 16 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,22 @@ def testfunc(n):
self.assertNotIn("_GUARD_NOS_NULL", uops)
self.assertNotIn("_GUARD_CALLABLE_TYPE_1", uops)

def test_call_type_1_result_is_const(self):
def testfunc(n):
x = 0
for _ in range(n):
t = type(42)
if t is not None: # guard is removed
x += 1
return x

res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
self.assertEqual(res, TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_CALL_TYPE_1", uops)
self.assertNotIn("_GUARD_IS_NOT_NONE_POP", uops)


def global_identity(x):
return x
Expand Down
Loading