Author terry.reedy
Recipients bruno.loff, congma, docs@python, terry.reedy
Date 2021-03-26.20:04:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1616789086.46.0.539040574613.issue43605@roundup.psfhosted.org>
In-reply-to
Content
This is not an execution bug.

https://docs.python.org/3/reference/expressions.html#displays-for-lists-sets-and-dictionaries

"However, aside from the iterable expression in the leftmost for clause, the comprehension is executed in a separate implicitly nested scope. This ensures that names assigned to in the target list don’t “leak” into the enclosing scope."

So when the passed in locals is not the passed in globals, that means a separate local scope.

https://docs.python.org/3/reference/expressions.html#generator-expressions is a little less clear.

"Variables used in the generator expression are evaluated lazily when the __next__() method is called for the generator object (in the same fashion as normal generators). However, the iterable expression in the leftmost for clause is immediately evaluated, so that an error produced by it will be emitted at the point where the generator expression is defined, rather than at the point where the first value is retrieved. Subsequent for clauses and any filter condition in the leftmost for clause cannot be evaluated in the enclosing scope as they may depend on the values obtained from the leftmost iterable."

By implication, the value expressions are also not evaluated in the enclosing local scope.

I am thinking about adding something to the eval/exec doc, but this issue overlaps with another one about their doc.





https://docs.python.org/3/reference/expressions.html#generator-expressions
History
Date User Action Args
2021-03-26 20:04:46terry.reedysetrecipients: + terry.reedy, docs@python, congma, bruno.loff
2021-03-26 20:04:46terry.reedysetmessageid: <1616789086.46.0.539040574613.issue43605@roundup.psfhosted.org>
2021-03-26 20:04:46terry.reedylinkissue43605 messages
2021-03-26 20:04:46terry.reedycreate