On 12 May 2018 at 14:13, Tim Peters <tim.peters@gmail.com> wrote:
Just clarifying a fine point here:

[Steven D'Aprano <steve@pearwood.info>]
> ...
> average = 0
> smooth_signal = [(average := (1-decay)*average + decay*x) for x in signal]
> assert average == smooth_signal[-1]
>

The scope issues are logically independent of assignment-expression
spelling, but it's a pretty safe guess Nick is opposed to that example
ever "just working" regardless of spelling, while PEP 572 doesn't
currently support it anyway.

I'm personally fine with that example working if there's an explicit nonlocal declaration on "average" in the nested scope - it's Guido that objected to requiring the explicit scoping declaration to access that behaviour.

For the implicit version, my request is that any PEP proposing the idea of parent local scoping be held to the standard of *actually drafting the patch for the language specification*, rather than handwaving away the hard problems that it creates (i.e. what to do at class scope, what to do when multiple generators expressions reference the same nonlocal name, what to do with nested comprehensions, how to expand comprehensions using this kind of scoping to their statement form in a context independent way).

Cheers,
Nick.

--
Nick Coghlan   |   ncoghlan@gmail.com   |   Brisbane, Australia