Now `for y in [expr]` in comprehensions is so fast as a simple assignment `y = expr`.
| break; | ||
| case Tuple_kind: | ||
| elts = gen->iter->v.Tuple.elts; | ||
| break; |
There was a problem hiding this comment.
How about we handle for x in {a} too?
There was a problem hiding this comment.
This will change the behavior if a is not hashable.
| @@ -0,0 +1,3 @@ | |||
| Optimized the idiom for assignment a temporary variable in comprehensions. | |||
| Now ``for y in [expr]`` in comprehensions is so fast as a simple assignment | |||
| ``y = expr``. | |||
There was a problem hiding this comment.
Please update the NEWS entry with some benchmark results.
There was a problem hiding this comment.
I'm not sure what should I provide. The optimized code always is the part of complex comprehension expression.
| compile("{x: y for y, x in ((1, 2), (3, 4))} += 5", "<test>", | ||
| "exec") | ||
|
|
||
| def test_assignment_idiom_in_comprehesions(self): |
Now
for y in [expr]in comprehensions is so fast as a simple assignmenty = expr.https://bugs.python.org/issue32856