On 21 April 2018 at 01:49, Chris Angelico <ros...@gmail.com> wrote:
> On Fri, Apr 20, 2018 at 10:51 PM, Paul Moore <p.f.mo...@gmail.com> wrote:
>> 2. I hadn't really thought of the PEP in those terms. Now that you've
>> mentioned it, "Python has never before had syntax that assigns names
>> from within an expression" is quite a significant change, and one the
>> PEP needs to examine the implications of. It's mostly been covered in
>> the discussions by now, of course.
> Depending on your definition of "assignment", a lambda function could
> count as a means of assigning a variable in a subexpression. But yes,
> there is no convenient way to assign to something in a wider scope.

We used to sort of have one (Python 2 list comprehensions), and the
behaviour was sufficiently unpopular that Py3 introduced an implicitly
nested scope to keep the iteration variable name from leaking :)

That history is a non-trivial part of why I advocated more strongly
for the original sublocal scoping version of the proposal: with
tighter lexical scoping for expression level assignments, I think we'd
be able to avoid most of the downsides that come from reinstating the
ability for expressions to bind and rebind names.

However, given how those original discussions went, I now think the
only way that option might be successfully pitched to people would be
to propose a statement-level variant of it first (perhaps in the form
of a heavily revised variant of PEP 3150's given clause), and then
only propose "expression level name binding with implicit sublocal
scopes" after the semantics of sublocal scoping were already
established elsewhere.


Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
Python-Dev mailing list

Reply via email to