mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
Bug #1520864 (again): unpacking singleton tuples in list comprehensions and
generator expressions (x for x, in ... ) works again. Sigh, I only fixed for loops the first time, not list comps and genexprs too. I couldn't find any more unpacking cases where there is a similar bug lurking. This code should be refactored to eliminate the duplication. I'm sure the listcomp/genexpr code can be refactored. I'm not sure if the for loop can re-use any of the same code though. Will backport to 2.5 (the only place it matters).
This commit is contained in:
parent
4bc2c0919b
commit
dac090d3e6
4 changed files with 23 additions and 5 deletions
|
@ -825,6 +825,10 @@ verify([(i,j) for i in range(10) for j in range(5)] == list(g))
|
|||
verify([ x for x in range(10) if x % 2 if x % 3 ], [1, 5, 7])
|
||||
verify((x for x in range(10) if x % 2 if x % 3), [1, 5, 7])
|
||||
|
||||
# Verify unpacking single element tuples in listcomp/genexp.
|
||||
vereq([x for x, in [(4,), (5,), (6,)]], [4, 5, 6])
|
||||
vereq(list(x for x, in [(7,), (8,), (9,)]), [7, 8, 9])
|
||||
|
||||
# Test ifelse expressions in various cases
|
||||
def _checkeval(msg, ret):
|
||||
"helper to check that evaluation of expressions is done correctly"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue