On Sun, Mar 25, 2018 at 2:48 PM, Ethan Furman <[email protected]> wrote:
> On 03/24/2018 01:35 AM, Nick Coghlan wrote:
>
>> In comprehensions and generator expressions, we'd need to explain why
>> inline assignments in the outermost iterator
>> expression leak but those in filter expressions, inner iterator
>> expressions, and result expressions don't.
>
>
> I don't understand -- could you give an example?
>

Let's suppose we have assignment expressions. I'm going to use "(expr
as name)" syntax for this example.

a = [(1 as b) for c in (d as e) if (2 as f)]

Which of these six names is local to the comprehension and which can
leak? Due to the requirements of class scope, 'd' must be looked up in
the outer scope. That means that its corresponding 'as e' must also
land in the outer scope. 'a', of course, is in the outer scope. The
other four are local to the inner function that implements the
comprehension.

ChrisA
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to