[Python-ideas] If branch merging

Ethan Furman ethan at stoneleaf.us
Fri Jun 12 16:14:05 CEST 2015

On 06/11/2015 11:55 PM, Stephen J. Turnbull wrote:
> Ethan Furman writes:
>> I would find the 'as NAME' portion very useful as long as it wasn't
>> shadowing nor unset.
> I don't understand the "not shadowing" requirement.  If you're not
> going to create a new scope, then
>   from foo import *
>   if expr as val:
>       use(val)
>   bar(val)
> might very well shadow foo.val and break the invocation of bar.  Is
> use of the identifier "val" in this context an error?  Or what?


    for val in some_iterator:


will shadow foo.val and break bar; yet for loops do not create their own scopes.

    with open('somefile') as val:
       stuff = val.read()


will also shadow foo.val and break bar, yet with contexts do not create their own scopes.

And let's not forget:

    val = some_func()


Again -- no micro-scope, and foo.val is shadowed.


More information about the Python-ideas mailing list