[issue32690] Return function locals() in order of creation?
Nick Coghlan
report at bugs.python.org
Sat Jan 27 23:48:11 EST 2018
Nick Coghlan <ncoghlan at gmail.com> added the comment:
The current oddity where the names will always appear in the reverse of declaration order comes from a C level loop in the frame object's "map_to_dict" helper function that loops in reverse [1]:
...
for (j = nmap; --j >= 0; ) {
...
}
While I haven't tried reversing that yet, I haven't found anything to indicate that it *needs* to be a reverse iteration - it looks like Guido just wrote it that way back in 1994 [2], and everyone that touched the code since then preserved the original iteration order since they didn't have a compelling reason to change it.
[1] https://github.com/python/cpython/blob/master/Objects/frameobject.c#L794
[2] https://github.com/python/cpython/commit/1d5735e84621a7fe68d361fa0e289fa2c3310836
----------
nosy: +ncoghlan
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32690>
_______________________________________
More information about the Python-bugs-list
mailing list