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.

Author Jim Fasarakis-Hilliard
Recipients Jim Fasarakis-Hilliard
Date 2017-02-25.19:54:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1488052483.04.0.021043093911.issue29652@psf.upfronthosting.co.za>
In-reply-to
Content
Reported from [1] and similar to issue11205 

Currently the evaluation order for keys and values in a dictionary comprehension follows that of assignments. The values get evaluated first and then the keys:

    def printer(v):
        print(v, end=' ')
        return v

    d = {printer(i): printer(j) for i, j in [(1, 2), (3, 4)]}
    # 2 1 4 3

This seems to conflict with the semantics as described in the Semantics section of PEP 274 [2] and according to my interpretation of the reference manual (I'd expect the evaluation to be similar to dict-displays).

How should this be addressed? Fix the evaluation order or specify this edge case an "Implementation detail" in the reference manual?

I already have a fix for this lying around (changes to `compiler_sync_comprehension_generator`, `compiler_sync_comprehension_generator` and a switch in `MAP_ADD`) and can make a pull request if required.

I'm not sure if this is classified as a bug per-se so I only tagged Py3.7 for it.

 [1] http://stackoverflow.com/questions/42201932/order-of-operations-in-a-dictionary-comprehension
 [2] https://www.python.org/dev/peps/pep-0274/#semantics
History
Date User Action Args
2017-02-25 19:54:43Jim Fasarakis-Hilliardsetrecipients: + Jim Fasarakis-Hilliard
2017-02-25 19:54:43Jim Fasarakis-Hilliardsetmessageid: <1488052483.04.0.021043093911.issue29652@psf.upfronthosting.co.za>
2017-02-25 19:54:43Jim Fasarakis-Hilliardlinkissue29652 messages
2017-02-25 19:54:42Jim Fasarakis-Hilliardcreate