diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-05-10 23:15:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-10 23:15:54 (GMT) |
commit | 93ef7aa03c64a97d8615ad3975083392ad07b379 (patch) | |
tree | 78e39cc2ec05fc13af5492d71a4618ddc762df9a /Objects | |
parent | 7dc9e923d1a33f40b94f535f9ccfdb9894a4ceb0 (diff) | |
download | cpython-93ef7aa03c64a97d8615ad3975083392ad07b379.zip cpython-93ef7aa03c64a97d8615ad3975083392ad07b379.tar.gz cpython-93ef7aa03c64a97d8615ad3975083392ad07b379.tar.bz2 |
[3.13] gh-118921: Add `copy()` method for `FrameLocalsProxy` (GH-118923) (#118933)
(cherry picked from commit 35c436186b849f8f2f9fb866c59015c9d034d448)
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/frameobject.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c index d7fcb19..64fded8 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -638,6 +638,23 @@ framelocalsproxy_setdefault(PyObject* self, PyObject *const *args, Py_ssize_t na } static PyObject* +framelocalsproxy_copy(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + PyObject* result = PyDict_New(); + + if (result == NULL) { + return NULL; + } + + if (PyDict_Update(result, self) < 0) { + Py_DECREF(result); + return NULL; + } + + return result; +} + +static PyObject* framelocalsproxy_reversed(PyObject *self, void *Py_UNUSED(ignored)) { PyObject *result = framelocalsproxy_keys(self, NULL); @@ -677,6 +694,8 @@ static PyMethodDef framelocalsproxy_methods[] = { NULL}, {"__reversed__", _PyCFunction_CAST(framelocalsproxy_reversed), METH_NOARGS, NULL}, + {"copy", _PyCFunction_CAST(framelocalsproxy_copy), METH_NOARGS, + NULL}, {"keys", _PyCFunction_CAST(framelocalsproxy_keys), METH_NOARGS, NULL}, {"values", _PyCFunction_CAST(framelocalsproxy_values), METH_NOARGS, |