bpo-32856: Optimize the assignment idiom in comprehensions. (GH-16814)
Now `for y in [expr]` in comprehensions is as fast as a simple
assignment `y = expr`.
diff --git a/Lib/test/test_genexps.py b/Lib/test/test_genexps.py
index fd712bb..86e4e19 100644
--- a/Lib/test/test_genexps.py
+++ b/Lib/test/test_genexps.py
@@ -15,6 +15,22 @@
>>> list((i,j) for i in range(4) for j in range(i) )
[(1, 0), (2, 0), (2, 1), (3, 0), (3, 1), (3, 2)]
+Test the idiom for temporary variable assignment in comprehensions.
+
+ >>> list((j*j for i in range(4) for j in [i+1]))
+ [1, 4, 9, 16]
+ >>> list((j*k for i in range(4) for j in [i+1] for k in [j+1]))
+ [2, 6, 12, 20]
+ >>> list((j*k for i in range(4) for j, k in [(i+1, i+2)]))
+ [2, 6, 12, 20]
+
+Not assignment
+
+ >>> list((i*i for i in [*range(4)]))
+ [0, 1, 4, 9]
+ >>> list((i*i for i in (*range(4),)))
+ [0, 1, 4, 9]
+
Make sure the induction variable is not exposed
>>> i = 20