From ca210861bec976b90278dcce9f3ff58e53425421 Mon Sep 17 00:00:00 2001 From: "Stan U." <89152624+StanFromIreland@users.noreply.github.com> Date: Sun, 24 Nov 2024 14:18:33 +0000 Subject: [PATCH 1/2] Update locals() docstring --- Python/bltinmodule.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 85ebd5b00cc18b..5b84da7a28b288 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1865,9 +1865,14 @@ locals as builtin_locals Return a dictionary containing the current scope's local variables. -NOTE: Whether or not updates to this dictionary will affect name lookups in -the local scope and vice-versa is *implementation dependent* and not -covered by any backwards compatibility guarantees. +In **non-optimized scopes** (e.g., module, class, `exec()`/`eval()`): + - Changes to the dictionary will affect the local variables, and vice versa. + +In **optimized scopes** (e.g., functions, generators, coroutines): + - The dictionary is a snapshot of local variables at the time of the call. + - Changes to the dictionary do not affect local variables, and changes to local variables are not reflected in the dictionary. + +NOTE: Behavior may vary by implementation, and changes to the dictionary in optimized scopes will not be reflected in local variables. [clinic start generated code]*/ static PyObject * From a2dcfb3510c7aa9d052e0ac51ee38e9400c101fc Mon Sep 17 00:00:00 2001 From: StanFromIreland Date: Sun, 8 Dec 2024 17:23:19 +0000 Subject: [PATCH 2/2] Run make clinic --- Python/bltinmodule.c | 2 +- Python/clinic/bltinmodule.c.h | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 505cfb72322d28..a8803bdc5eeeed 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1882,7 +1882,7 @@ NOTE: Behavior may vary by implementation, and changes to the dictionary in opti static PyObject * builtin_locals_impl(PyObject *module) -/*[clinic end generated code: output=b46c94015ce11448 input=7874018d478d5c4b]*/ +/*[clinic end generated code: output=b46c94015ce11448 input=c673cc693bc4ed02]*/ { return _PyEval_GetFrameLocals(); } diff --git a/Python/clinic/bltinmodule.c.h b/Python/clinic/bltinmodule.c.h index 7d348dbebed385..881fa7bdc077b2 100644 --- a/Python/clinic/bltinmodule.c.h +++ b/Python/clinic/bltinmodule.c.h @@ -781,9 +781,14 @@ PyDoc_STRVAR(builtin_locals__doc__, "\n" "Return a dictionary containing the current scope\'s local variables.\n" "\n" -"NOTE: Whether or not updates to this dictionary will affect name lookups in\n" -"the local scope and vice-versa is *implementation dependent* and not\n" -"covered by any backwards compatibility guarantees."); +"In **non-optimized scopes** (e.g., module, class, `exec()`/`eval()`):\n" +" - Changes to the dictionary will affect the local variables, and vice versa.\n" +"\n" +"In **optimized scopes** (e.g., functions, generators, coroutines):\n" +" - The dictionary is a snapshot of local variables at the time of the call.\n" +" - Changes to the dictionary do not affect local variables, and changes to local variables are not reflected in the dictionary.\n" +"\n" +"NOTE: Behavior may vary by implementation, and changes to the dictionary in optimized scopes will not be reflected in local variables."); #define BUILTIN_LOCALS_METHODDEF \ {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__}, @@ -1239,4 +1244,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=b0178189d13e8bf8 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3278ccdf4dd07c2d input=a9049054013a1b77]*/