Skip to content

bpo-32856: Optimize the assignment idiom in comprehensions. #16814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Oct 15, 2019

Now for y in [expr] in comprehensions is so fast as a simple assignment y = expr.

Unlike to the := operator this idiom does not leak a variable to the outer scope.

https://bugs.python.org/issue32856

@serhiy-storchaka serhiy-storchaka added the performance Performance or resource usage label Oct 15, 2019
@serhiy-storchaka serhiy-storchaka changed the title Optimize assignment idiom in comprehensions bpo-32856: Optimize the assignment idiom in comprehensions. Oct 15, 2019
Copy link
Contributor

@scoder scoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have an opinion on the general feature, so just a few comments.

@@ -227,6 +227,17 @@ signals to a process using a file descriptor instead of a pid. (:issue:`38712`)
Optimizations
=============

* Optimized the idiom for assignment a temporary variable in comprehensions.
Now ``for y in [expr]`` in comprehensions is so fast as a simple assignment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"as fast as" (also in news file)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thank you.

@scoder
Copy link
Contributor

scoder commented Jan 12, 2020

LGTM

@serhiy-storchaka serhiy-storchaka merged commit 8c579b1 into python:master Feb 12, 2020
@serhiy-storchaka serhiy-storchaka deleted the optimize-assignment-in-comprehensions branch February 12, 2020 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants