[Python-ideas] Inline assignments using "given" clauses
ncoghlan at gmail.com
Sun May 13 23:58:15 EDT 2018
On 12 May 2018 at 14:13, Tim Peters <tim.peters at gmail.com> wrote:
> Just clarifying a fine point here:
> [Steven D'Aprano <steve at pearwood.info>]
> > ...
> > average = 0
> > smooth_signal = [(average := (1-decay)*average + decay*x) for x in
> > 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
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).
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas