Skip to content

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

Merged
serhiy-storchaka merged 12 commits intopython:masterfrom
serhiy-storchaka:optimize-assignment-in-comprehensions
Feb 12, 2020
Merged

bpo-32856: Optimize the assignment idiom in comprehensions.#16814
serhiy-storchaka merged 12 commits intopython:masterfrom
serhiy-storchaka:optimize-assignment-in-comprehensions

Conversation

@serhiy-storchaka
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread Doc/whatsnew/3.9.rst Outdated
=============

* 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
Copy Markdown
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
Copy Markdown
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.

Comment thread Python/compile.c
@scoder
Copy link
Copy Markdown
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