Repository navigation
Backport set and dict comprehensions #46586
Description
Activity
Dict comprehensions need to be backported.
- addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errorand removed
on Mar 17, 2008 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.- changed the title
[-]Backport dict comprehensions[/-][+]Backport set and dict comprehensions[/+]on Aug 5, 2009 Alexandre, I can't get this to apply cleanly to my svn trunk checkout
(r74328) (see attached log). Am I doing something stupid?You need to apply the set literal patch I posted in bpo-2335 first.
Ah, that works. Thanks! (I'll pay more attention to the tracker
Dependencies field in future.)If there are no objections, I will commit this patch later this week
after issue bpo-2335.Committed in r77422.
How about fixing set.__repr__ ?
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.
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?
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 bpo-2335.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: