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

Chris Angelico rosuav at gmail.com
Sun Mar 25 21:29:52 EDT 2018


On Mon, Mar 26, 2018 at 12:24 PM, Guido van Rossum <guido at python.org> wrote:
> I gotta say I'm warming up to := in preference over 'as', *if* we're going
> to do this at all (not a foregone conclusion at all).

So am I, primarily due to its lack of syntactic ambiguities.

> The scope question is far from easy though. I find it particularly grating
> that an inline assignment occurs in an 'if' statement, its scope is the
> entire body of the 'if'. If that body is two pages long, by the end of it
> the reader (or even the writer!) may well have lost track of where it was
> defined and may be confused by the consequence past the end of the body.

I think this one can be given to style guides. The useful situations
(eg regex match capturing) are sufficiently valuable that the
less-useful ones can just come along for the ride, just like "x =
lambda: ..." is perfectly valid even though "def" would be preferable.

ChrisA


More information about the Python-ideas mailing list