[Python-Dev] Dictionary evaluation order
Gustavo Niemeyer
niemeyer@conectiva.com
Tue, 26 Nov 2002 02:33:36 -0200
I was just looking at the bug
[#448679] Left to right
It mentions that code like that
{f1():f2(), f3():f4()}
Will call these functions in the order f2, f1, f4, f3. What should we
do about it? Tim mentions that "When [Tim] asked Guido about that
some years ago, he agreed it was a bug.". Is it too late to fix it, or
is it still a desirable fix?
The fix should be as easy as that:
diff -u -r2.264 compile.c
--- Python/compile.c 3 Oct 2002 09:50:47 -0000 2.264
+++ Python/compile.c 26 Nov 2002 04:02:27 -0000
@@ -1527,9 +1527,9 @@
It wants the stack to look like (value) (dict) (key) */
com_addbyte(c, DUP_TOP);
com_push(c, 1);
- com_node(c, CHILD(n, i+2)); /* value */
- com_addbyte(c, ROT_TWO);
com_node(c, CHILD(n, i)); /* key */
+ com_node(c, CHILD(n, i+2)); /* value */
+ com_addbyte(c, ROT_THREE);
com_addbyte(c, STORE_SUBSCR);
com_pop(c, 3);
}
(compiler module should be fixed as well, as it mimicks that behavior)
So I belive it just a matter of deciding what should be done.
--
Gustavo Niemeyer
[ 2AAC 7928 0FBF 0299 5EB5 60E2 2253 B29A 6664 3A0C ]