bpo-32856: Optimize the idiom for assignment in comprehensions.#5695
Closed
serhiy-storchaka wants to merge 5 commits intopython:masterfrom
Closed
bpo-32856: Optimize the idiom for assignment in comprehensions.#5695serhiy-storchaka wants to merge 5 commits intopython:masterfrom
serhiy-storchaka wants to merge 5 commits intopython:masterfrom
Conversation
Now `for y in [expr]` in comprehensions is so fast as a simple assignment `y = expr`.
1st1
reviewed
Feb 16, 2018
| break; | ||
| case Tuple_kind: | ||
| elts = gen->iter->v.Tuple.elts; | ||
| break; |
Member
There was a problem hiding this comment.
How about we handle for x in {a} too?
Member
Author
There was a problem hiding this comment.
This will change the behavior if a is not hashable.
1st1
reviewed
Feb 16, 2018
| @@ -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``. | |||
Member
There was a problem hiding this comment.
Please update the NEWS entry with some benchmark results.
Member
Author
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.
cpitclaudel
reviewed
Feb 22, 2018
Lib/test/test_dictcomps.py
Outdated
| compile("{x: y for y, x in ((1, 2), (3, 4))} += 5", "<test>", | ||
| "exec") | ||
|
|
||
| def test_assignment_idiom_in_comprehesions(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Now
for y in [expr]in comprehensions is so fast as a simple assignmenty = expr.https://bugs.python.org/issue32856