Skip to content
Merged
Prev Previous commit
Next Next commit
Test for FOR_ITER_TUPLE Tier 2
  • Loading branch information
gvanrossum committed Jul 12, 2023
commit 173cc7c448981312613dc8bd941cafd2f449f856
22 changes: 22 additions & 0 deletions Lib/test/test_capi/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2627,6 +2627,28 @@ def testfunc(a):
# Verification that the jump goes past END_FOR
# is done by manual inspection of the output

def test_for_iter_tuple(self):
def testfunc(a):
total = 0
for i in a:
total += i
return total

opt = _testinternalcapi.get_uop_optimizer()
with temporary_optimizer(opt):
a = tuple(range(10))
total = testfunc(a)
self.assertEqual(total, 45)

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
# for i, (opname, oparg) in enumerate(ex):
# print(f"{i:4d}: {opname:<20s} {oparg:3d}")
uops = {opname for opname, _ in ex}
self.assertIn("_ITER_EXHAUSTED_TUPLE", uops)
# Verification that the jump goes past END_FOR
# is done by manual inspection of the output


if __name__ == "__main__":
unittest.main()