]> granicus.if.org Git - python/commitdiff
bpo-32690: Preserve order of locals() (#5379)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Sun, 28 Jan 2018 17:40:24 +0000 (09:40 -0800)
committerGitHub <noreply@github.com>
Sun, 28 Jan 2018 17:40:24 +0000 (09:40 -0800)
Misc/NEWS.d/next/Core and Builtins/2018-01-28-09-26-07.bpo-32690.8i9g5P.rst [new file with mode: 0644]
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 (file)
index 0000000..1663b96
--- /dev/null
@@ -0,0 +1,2 @@
+The locals() dictionary now displays in the lexical order that variables
+were defined.  Previously, the order was reversed.
index 1ac3d752575268c08edd9d6510cf5f0ef36e4c57..3083e5b6445c29bebc5932f691a10af26212a89c 100644 (file)
@@ -791,7 +791,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));
@@ -844,7 +844,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));