[Python-ideas] An alternative to PEP 572's Statement-Local Name Bindings

Paul Moore p.f.moore at gmail.com
Sat Mar 3 05:32:28 EST 2018


On 3 March 2018 at 07:45, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On 3 March 2018 at 11:36, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>>
>> 1. Name bindings local to an expression:
>>
>>    roots = ([(-b-r)/(2*a), (-b+r)/(2*a)] where r = sqrt(b*b-4*a*c))
>>
>> B. In an expression, surrounded by parentheses for
>> disambiguation. Bindings are visible only within the
>> parentheses.
>
>
> I'll note that a significant benefit of this approach over the PEP 572
> approach is that it would be amenable to a comprehension style
> scope-management solution: these expressions could create an implicitly
> nested function and immediately call it, just as 3.x comprehensions do.
> Adopting such an approach would *dramatically* lower the impact that hiding
> the bindings from the surrounding scope would have on the overall name
> resolution semantics.

While I'm *still* not sure any of this provides enough benefit to be
worth doing, I will say that this proposal feels far less complicated
than PEP 572. I don't particularly like the extension to if and while
statements (and it's been mentioned that there are remarkably few
cases where the value you want to capture is the actual condition
rather than a value the condition tests) but otherwise I'm OK with it
(call me -0 on the proposal without if/while, and -0.5 on the if/while
part).

Paul


More information about the Python-ideas mailing list