On 2018-05-31 05:53, Steven D'Aprano wrote:
Bottom line is, if you think it is okay that the following assignment to
x affects the local scope:

     results = []
     for a in seq:
         # using "given" to avoid arguments about :=
         y = (x given x = a)+1
     assert "x" in locals()

but then worry that changing the loop to a comprehension:

     results = [(x given x = a)+1 for a in seq]
     assert "x" in locals()

will be a problem, then I think you are applying an unreasonably strict
standard of functional purity towards comprehensions, one which is not
justified by Python's consenting adults approach to side-effects or the
fact that comprehensions can already have side-effects.

What I don't understand is this: if we believe that, then why was comprehension-leaking EVER removed? Everything that I've seen advocating for this kind of leaking seems to me like it is much more logically consistent with allowing all comprehension variables to leak than it is with the current behavior, in which they don't leak.

Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail."
   --author unknown
Python-ideas mailing list
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to