[Python-ideas] PEP 572: Statement-Local Name Bindings, take three!

Chris Angelico rosuav at gmail.com
Sun Mar 25 19:54:31 EDT 2018


On Mon, Mar 26, 2018 at 10:40 AM, Tim Peters <tim.peters at gmail.com> wrote:
> Here's one that baffled an office full of MIT grads for half a day
> before I noticed the real problem:
>
>     assert(n=2);
>
> You can fill in the rest of the story yourself - but you'll miss the
> full extent of the agony it caused ;-)

I have to confess that my eye jumped down to the code before reading
all of the text above it, and as a result, I thought you were pointing
out that "n=2" for assignment would conflict with named argument
usage. Which it does, but that wasn't your point :)

Is there any way that ":=" can legally occur in Python source
(ignoring string literals) currently? A colon is always followed by a
'suite' or a 'test', neither of which can start with '=', and
annotated assignment has to have something between the ':' and '='. If
it's 100% unambiguous, it could be the solution to the current
wonkiness with 'as' having multiple meanings; in fact, there would
then be a new form of consistency: 'as' binds the special result of a
statement, but ':=' binds arbitrary expressions.

ChrisA


More information about the Python-ideas mailing list