summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTian Gao <gaogaotiantian@hotmail.com>2024-05-05 03:06:42 (GMT)
committerGitHub <noreply@github.com>2024-05-05 03:06:42 (GMT)
commit5dd36732c850084ce262b7869ed90d73a281296a (patch)
treef6927d57c949dda62f28daeb191d53cb8029a6f4
parent1b22d801b86ed314c4804b19a1fc4b13484e3cea (diff)
downloadcpython-5dd36732c850084ce262b7869ed90d73a281296a.zip
cpython-5dd36732c850084ce262b7869ed90d73a281296a.tar.gz
cpython-5dd36732c850084ce262b7869ed90d73a281296a.tar.bz2
gh-74929: Remove undesirable DECREF in PEP 667 implementation (#118583)
With tests.
-rw-r--r--Lib/test/test_frame.py15
-rw-r--r--Objects/frameobject.c1
2 files changed, 15 insertions, 1 deletions
diff --git a/Lib/test/test_frame.py b/Lib/test/test_frame.py
index 93d0ea8..2122553 100644
--- a/Lib/test/test_frame.py
+++ b/Lib/test/test_frame.py
@@ -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
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 8030ecb..1cb00e3 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -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;
}
}