[Python-checkins] bpo-32690: Preserve order of locals() (GH-5379) (#5390)

Raymond Hettinger webhook-mailer at python.org
Sun Jan 28 13:13:20 EST 2018


https://github.com/python/cpython/commit/9105879bfd7133ecbac67f3e9c0bacf6e477de5a
commit: 9105879bfd7133ecbac67f3e9c0bacf6e477de5a
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Raymond Hettinger <rhettinger at users.noreply.github.com>
date: 2018-01-28T10:13:17-08:00
summary:

bpo-32690: Preserve order of locals() (GH-5379) (#5390)

(cherry picked from commit a4d00012565d716db6e6abe1b8f33eaaa4de416e)

files:
A Misc/NEWS.d/next/Core and Builtins/2018-01-28-09-26-07.bpo-32690.8i9g5P.rst
M Objects/frameobject.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-01-28-09-26-07.bpo-32690.8i9g5P.rst b/Misc/NEWS.d/next/Core and Builtins/2018-01-28-09-26-07.bpo-32690.8i9g5P.rst
new file mode 100644
index 000000000000..1663b96cb927
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2018-01-28-09-26-07.bpo-32690.8i9g5P.rst	
@@ -0,0 +1,2 @@
+The locals() dictionary now displays in the lexical order that variables
+were defined.  Previously, the order was reversed.
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 62f9f34c8ebf..ca1fbfa1a28f 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -776,7 +776,7 @@ map_to_dict(PyObject *map, Py_ssize_t nmap, PyObject *dict, PyObject **values,
     assert(PyTuple_Check(map));
     assert(PyDict_Check(dict));
     assert(PyTuple_Size(map) >= nmap);
-    for (j = nmap; --j >= 0; ) {
+    for (j=0; j < nmap; j++) {
         PyObject *key = PyTuple_GET_ITEM(map, j);
         PyObject *value = values[j];
         assert(PyUnicode_Check(key));
@@ -829,7 +829,7 @@ dict_to_map(PyObject *map, Py_ssize_t nmap, PyObject *dict, PyObject **values,
     assert(PyTuple_Check(map));
     assert(PyDict_Check(dict));
     assert(PyTuple_Size(map) >= nmap);
-    for (j = nmap; --j >= 0; ) {
+    for (j=0; j < nmap; j++) {
         PyObject *key = PyTuple_GET_ITEM(map, j);
         PyObject *value = PyObject_GetItem(dict, key);
         assert(PyUnicode_Check(key));



More information about the Python-checkins mailing list