On Thu, Jul 5, 2018 at 10:20 AM, Steve Dower <steve.do...@python.org> wrote: > On 04Jul2018 1518, Tim Peters wrote: >> The only new thing is specifying the scope of `a`, where "local to f" >> means exactly the same thing as for any other name local to a function >> today. So far as the PEP semantics go, it doesn't even matter whether >> an implementation _does_ implement some form of closure as such. It >> just has to provide the visible semantics of _lexically_ nested scopes >> with indefinite extent, by whatever means it likes best. That's what >> "local to f" means (and has meant all along - well, since lexically >> nested scopes were first introduced). > > In that case, please provide more examples of how it should work when > the assignment expression appears to define a variable in a scope that > is not on the call stack.
Using an assignment expression in a comprehension is the same as using an assignment expression outside a comprehension at the exact same point in the code. I'm not sure what else needs to be explained further. It's assignment, so it creates a name at that scope. > For example, what should be returned from this function? > > >>> A = 0 > >>> def f(x): > ... if x: > ... [A := i for i in [1]] > ... return A A would be local to f(). This will either return 1 or raise UnboundLocalError; it will never return 0. ChrisA _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com