This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Left to right
Type: Stage:
Components: Documentation Versions: Python 2.3
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: niemeyer Nosy List: loewis, niemeyer, tim.peters
Priority: normal Keywords:

Created on 2001-08-07 06:55 by tim.peters, last changed 2022-04-10 16:04 by admin. This issue is now closed.

File name Uploaded Description Edit
ref5.diff loewis, 2002-08-04 09:58
evalorder.patch niemeyer, 2002-11-26 22:56
Messages (6)
msg5810 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2001-08-07 06:55
The Ref Man doesn't explicitly say anything about 
Python's left-to-right evaluation order.  Strict left-
to-right was Guido's intent, though, and it comes up a 
few times per year on (indeed, I was just 
replying to a msg asking about it).

The docs should get fleshed out.

There's also a bug:

>>> counter = 0
>>> def i():
...     global counter
...     counter += 1
...     return counter
>>> {i(): i()}
{2: 1}
>>> {i(): i(), i(): i()}
{4: 3, 6: 5}

That is, key:value *pairs* are evaluated left to 
right, but within a single key:value pair, the value 
gets evaluated first.  When I asked Guido about that 
some years ago, he agreed it was a bug.
msg5811 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-08-04 09:58
Logged In: YES 

With the patch attached, this behaviour is cast into stone
(or, atleast into a SF tracker :)
msg5812 - (view) Author: Gustavo Niemeyer (niemeyer) * (Python committer) Date: 2002-11-26 22:56
Logged In: YES 

I'm attaching a suggested solution for the problem,
including documentation and reordering of dict evaluation.
msg5813 - (view) Author: Gustavo Niemeyer (niemeyer) * (Python committer) Date: 2002-12-01 02:05
Logged In: YES 

Martin, could you please review the proposed solution?
msg5814 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-12-02 10:58
Logged In: YES 

The patch looks fine, please apply it.

It would be good to check that Jython meets all your 
expectations in this respect, and that it, in particular, 
executes all the examples in the documentation in the right 

This change should *not* be backported to 2.2 IMO.
msg5815 - (view) Author: Gustavo Niemeyer (niemeyer) * (Python committer) Date: 2002-12-16 14:05
Logged In: YES 

Martin, I've checked with Jython and the examples are ok as

I have applied as:

Doc/ref/ref5.tex: 1.71
Python/compile.c: 2.267
Lib/compiler/ 1.62
Misc/NEWS: 1.561

Thank you!
Date User Action Args
2022-04-10 16:04:17adminsetgithub: 34910
2001-08-07 06:55:27tim.peterscreate