gh-74929: Remove undesirable DECREF in PEP 667 implementation (#118583)

With tests.
This commit is contained in:
Tian Gao 2024-05-04 20:06:42 -07:00 committed by GitHub
parent 1b22d801b8
commit 5dd36732c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -364,6 +364,21 @@ class TestFrameLocals(unittest.TestCase):
c = 0 c = 0
f() 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): def test_repr(self):
x = 1 x = 1
# Introduce a reference cycle # Introduce a reference cycle

View File

@ -171,7 +171,6 @@ framelocalsproxy_setitem(PyObject *self, PyObject *key, PyObject *value)
} else if (value != oldvalue) { } else if (value != oldvalue) {
Py_XSETREF(fast[i], Py_NewRef(value)); Py_XSETREF(fast[i], Py_NewRef(value));
} }
Py_XDECREF(value);
return 0; return 0;
} }
} }