[Python-checkins] gh-104635: Add a test case for variables that have a dependency. (gh-106583)

corona10 webhook-mailer at python.org
Mon Jul 10 21:14:56 EDT 2023


https://github.com/python/cpython/commit/115df8491a6633ced3cc3f2343b349869de30b8c
commit: 115df8491a6633ced3cc3f2343b349869de30b8c
branch: main
author: Dong-hee Na <donghee.na at python.org>
committer: corona10 <donghee.na92 at gmail.com>
date: 2023-07-11T10:14:53+09:00
summary:

gh-104635: Add a test case for variables that have a dependency. (gh-106583)

files:
M Lib/test/test_compile.py

diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 784c0550cc09b..85ce0a4b39d85 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -1186,6 +1186,15 @@ def f(x, y, z):
             return a
         self.assertEqual(f("x", "y", "z"), "y")
 
+    def test_variable_dependent(self):
+        # gh-104635: Since the value of b is dependent on the value of a
+        # the first STORE_FAST for a should not be skipped. (e.g POP_TOP).
+        # This test case is added to prevent potential regression from aggressive optimization.
+        def f():
+            a = 42; b = a + 54; a = 54
+            return a, b
+        self.assertEqual(f(), (54, 96))
+
 
 @requires_debug_ranges()
 class TestSourcePositions(unittest.TestCase):



More information about the Python-checkins mailing list