]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-74929: Remove undesirable DECREF in PEP 667 implementation (#118583)
authorTian Gao <gaogaotiantian@hotmail.com>
Sun, 5 May 2024 03:06:42 +0000 (20:06 -0700)
committerGitHub <noreply@github.com>
Sun, 5 May 2024 03:06:42 +0000 (03:06 +0000)
With tests.

Lib/test/test_frame.py
Objects/frameobject.c

index 93d0ea839d16eb1d6b45389e0d67438bc503e425..212255374bddd1c80fd27d039e189bc885fe69b6 100644 (file)
@@ -364,6 +364,21 @@ class TestFrameLocals(unittest.TestCase):
             c = 0
         f()
 
+    def test_local_objects(self):
+        o = object()
+        k = '.'.join(['a', 'b', 'c'])
+        f_locals = sys._getframe().f_locals
+        f_locals['o'] = f_locals['k']
+        self.assertEqual(o, 'a.b.c')
+
+    def test_update_with_self(self):
+        def f():
+            f_locals = sys._getframe().f_locals
+            f_locals.update(f_locals)
+            f_locals.update(f_locals)
+            f_locals.update(f_locals)
+        f()
+
     def test_repr(self):
         x = 1
         # Introduce a reference cycle
index 8030ecb685367475e9f7a057dde78e5d10ecb1a6..1cb00e318d9163b79a5ded078145564135fa539e 100644 (file)
@@ -171,7 +171,6 @@ framelocalsproxy_setitem(PyObject *self, PyObject *key, PyObject *value)
             } else if (value != oldvalue) {
                 Py_XSETREF(fast[i], Py_NewRef(value));
             }
-            Py_XDECREF(value);
             return 0;
         }
     }