osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] Examples for PEP 572


On 2018-07-04 00:25, Nathaniel Smith wrote:
> The only cases that seem potentially valuable to me are the ones that
> are literally the form 'if <name> := <expr>` and 'while <name> :=
> <expr>'. (I suspect these are the only cases that I would allow in
> code that I maintain.) The PEP does briefly discuss the alternative
> proposal of restricting to just these two cases, but rejects it
> because it would rule out code like 'if (<name> := <expr>)
> <comparison> <expr>'. But those are exactly the cases that I want to
> rule out, so that seems like a plus to me :-).
> 
> The 'if <expr> as <name>' syntax would be a simple way to encode
> exactly these simple non-harmful cases. The PEP rejects it on the
> grounds that 'as' is already used in a different way by 'except' and
> 'with'. But... 'as' is *also* used in the *same* way by 'import', so
> the argument feels disingenuous. Yeah, there'd be an inconsistency,
> but that inconsistency already exists, and adding 'if ... as' and
> 'while ... as' wouldn't create any *new* inconsistencies.


Agreed, tried to make this point in several threads.

-Mike