[Python-Dev] chained assignment weirdity

Guido van Rossum guido at python.org
Tue Nov 6 23:12:40 CET 2012

On Tue, Nov 6, 2012 at 9:58 AM, Ned Batchelder <ned at nedbatchelder.com> wrote:
> On 11/6/2012 11:26 AM, R. David Murray wrote:
>> On Tue, 06 Nov 2012 18:14:38 +0200, Serhiy Storchaka <storchaka at gmail.com>
>> wrote:
>>> Another counterintuitive (and possible wrong) example:
>>>     >>> {print('foo'): print('bar')}
>>>     bar
>>>     foo
>>>     {None: None}
>> http://bugs.python.org/issue11205
> This seems to me better left undefined, since there's hardly ever a need to
> know the precise evaluation sequence between keys and values, and retaining
> some amount of "unspecified" to allow for implementation flexibility is a
> good thing.

Maybe. Do note that Python tries to be *different* than your average
C++ standard and actually prescribes evaluation orders in most cases.
The idea being that the kind of optimizations that C++ compilers get
to do by moving evaluation order around aren't worth it in Python
anyway, and it's better for the user if there are no arbitrary
differences in this area between Python implementations. Note that I
didn't say "no surprises" -- the post that started this thread shows
that surprises are still possible.

--Guido van Rossum (python.org/~guido)

More information about the Python-Dev mailing list