[issue10544] yield expression inside generator expression does nothing

Serhiy Storchaka report at bugs.python.org
Thu Nov 23 07:00:03 EST 2017


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

Consider this as a sort of optimization. A function inlining. In general case we can't inline a function because it can be rebinded at any time, but in this particular case we call a just created function that doesn't have any references and live only on the stack a, and we have all information for generating an inlined code. This will allow to get rid of the overhead for creating and calling a one-time function.

The naming problem is the hardest problem. We should assign unique names for internal variables, like '.0.x'. We already do this for the single parameter of a one-time function. Or we could just use a stack (this requires more work but has additional benefits).

If you want to think about comprehensions as about calling inner functions, you can do this. And you can think about comprehensions as about loops which don't leak inner variables. The behavior should be absolutely identical until you will use "yield" which would turn your list producing function into a generator. If make "yield" turning into a generator not an implicit inner function, but an explicit enclosing function, a comprehension could be represented via an implicit inner function. Currently there is no way to express this in Python syntax, but before introducing "yield" there was no way to express its semantic.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue10544>
_______________________________________


More information about the Python-bugs-list mailing list