[Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

Nick Coghlan ncoghlan at gmail.com
Mon Apr 16 12:34:25 EDT 2018


On 16 April 2018 at 00:27, Thautwarm Zhao <yaoxiansamma at gmail.com> wrote:
> Personally I prefer "as", but I think without a big change of python Grammar
> file, it's impossible to avoid parsing "with expr as name" into "with (expr
> as name)" because "expr as name" is actually an "expr".
> I have mentioned this in previous discussions and it seems it's better to
> warn you all again. I don't think people of Python-Dev are willing to
> implement a totally new Python compiler.

We have ways of cheating a bit if we want to reinterpret the semantics
of something that nevertheless parses cleanly - while the parser is
limited to single token lookahead, it's straightforward for the
subsequent code generation stage to look a single level down in the
parse tree and see that the code that parsed as "with expr" is
actually "with subexpr as target".

So the main concern around "with (name as expr)" is with human readers
getting confused, not the compiler, as we can tell the latter to
implement whichever semantics we decide we want, while humans are far
less tractable :)

Cheers,
Nick.

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


More information about the Python-ideas mailing list