From 075dbe085a87d84c31466f2d72bc7737e9b06eb1 Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Tue, 12 Dec 2023 23:26:07 -0500 Subject: [PATCH] Add a test --- library/_compile_test.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/library/_compile_test.py b/library/_compile_test.py index 48aec6269..a112a150f 100644 --- a/library/_compile_test.py +++ b/library/_compile_test.py @@ -1706,6 +1706,26 @@ def foo(): """) self.assertEqual(func(), {"x": 123}) + def test_store_self_removes_last_store(self): + # TODO(max): See if we can remove the first store too + source = """ +def foo(): + x = 123 + x = x +""" + func = compile_function(source, "foo") + self.assertEqual( + dis(func.__code__), + """\ +LOAD_CONST 123 +STORE_FAST_REVERSE x +LOAD_FAST_REVERSE_UNCHECKED x +POP_TOP +LOAD_CONST None +RETURN_VALUE +""") + self.assertEqual(func(), None) + # TODO(max): Test loops