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.

classification
Title: Backport set and dict comprehensions
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 2.7
process
Status: closed Resolution: accepted
Dependencies: 2335 Superseder:
Assigned To: Nosy List: alexandre.vassalotti, brett.cannon, ezio.melotti, fossilet, mark.dickinson, metal
Priority: critical Keywords: 26backport, patch

Created on 2008-03-17 17:37 by brett.cannon, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
backport_dict_and_set_comprehension.diff alexandre.vassalotti, 2009-08-05 23:10
patch_failure.log mark.dickinson, 2009-08-06 16:24 Output of attempt to apply patch.
set_and_dict_comprehensions.diff fossilet, 2012-11-14 06:56 review
Messages (11)
msg63690 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-03-17 17:37
Dict comprehensions need to be backported.
msg91338 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2009-08-05 23:09
Here is a patch to backport dict and set comprehensions to the trunk.

The patch preserves the Python 3.x's syntax and semantics of the
feature. Although this makes dict and set comprehensions is inconsistent
with list comprehension, I believe this is reasonable since the backport
aimed to improve the compatibility of Python 2.x with Python 3.x.

The patch also adds support for dict and set comprehensions to the
'compiler' package. However, the support is quirky and use the list
comprehension semantics of Python 2.x. This allowed me to keep the patch
simple and to keep myself sane ;-).

Finally, the patch changes the name of the following syntax nodes:
'gen_expr', 'gen_iter', 'gen_if', and 'testlist_gexp'. I don't know if
we have compatibility requirements for this; so I don't know if this is
an issue.
msg91367 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-08-06 16:24
Alexandre, I can't get this to apply cleanly to my svn trunk checkout 
(r74328) (see attached log).  Am I doing something stupid?
msg91368 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2009-08-06 16:44
You need to apply the set literal patch I posted in issue2335 first.
msg91369 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-08-06 16:52
Ah, that works.  Thanks!  (I'll pay more attention to the tracker 
Dependencies field in future.)
msg96257 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2009-12-11 14:15
If there are no objections, I will commit this patch later this week
after issue #2335.
msg97611 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2010-01-11 22:36
Committed in r77422.
msg112812 - (view) Author: METAL XXX (metal) Date: 2010-08-04 14:32
How about fixing set.__repr__ ?
msg175539 - (view) Author: Yongzhi Pan (fossilet) * Date: 2012-11-14 06:56
Great they are backported to 2.7.  Dictionary and set comprehensions are not documented in the tutorial of 2.7, though they are in the language reference. Is it OK to add these to the tutorial? I've uploaded a patch.
msg175541 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-11-14 07:07
> Is it OK to add these to the tutorial? I've uploaded a patch.

Yes, but please create a new issue.

> How about fixing set.__repr__ ?

Is it broken?
msg175554 - (view) Author: Yongzhi Pan (fossilet) * Date: 2012-11-14 09:00
I think metal means that the different ways set is repr'd in 2.7 and 3.

In 2.7:

In [9]: a = {x for x in 'abracadabra' if x not in 'abc'}

In [10]: repr(a)
Out[10]: "set(['r', 'd'])"

In 3.2:
In [6]: a = {x for x in 'abracadabra' if x not in 'abc'}

In [7]: repr(a)
Out[7]: "{'r', 'd'}"

We were saying not changing __repr__ in #2335.
History
Date User Action Args
2022-04-11 14:56:31adminsetgithub: 46586
2012-11-14 09:00:10fossiletsetmessages: + msg175554
2012-11-14 07:07:52ezio.melottisetmessages: + msg175541
2012-11-14 06:56:46fossiletsetfiles: + set_and_dict_comprehensions.diff
nosy: + fossilet
messages: + msg175539

2010-08-04 14:39:04ezio.melottisetnosy: + ezio.melotti
2010-08-04 14:32:53metalsetnosy: + metal
messages: + msg112812
2010-01-11 22:36:41alexandre.vassalottisetstatus: open -> closed
resolution: accepted
messages: + msg97611

stage: patch review -> resolved
2009-12-11 14:15:09alexandre.vassalottisetmessages: + msg96257
2009-08-06 16:52:11mark.dickinsonsetmessages: + msg91369
2009-08-06 16:44:07alexandre.vassalottisetmessages: + msg91368
2009-08-06 16:24:07mark.dickinsonsetfiles: + patch_failure.log
nosy: + mark.dickinson
messages: + msg91367

2009-08-05 23:12:32alexandre.vassalottisetdependencies: + Backport set literals
2009-08-05 23:11:45alexandre.vassalottilinkissue2334 superseder
2009-08-05 23:10:11alexandre.vassalottisetfiles: + backport_dict_and_set_comprehension.diff

title: Backport dict comprehensions -> Backport set and dict comprehensions
keywords: + patch
nosy: + alexandre.vassalotti

messages: + msg91338
stage: patch review
2008-08-21 14:51:46benjamin.petersonsetversions: + Python 2.7, - Python 2.6
2008-03-17 20:10:00brett.cannonsetpriority: release blocker -> critical
2008-03-17 17:37:33brett.cannoncreate