[Python-ideas] If branch merging

Ethan Furman ethan at stoneleaf.us
Fri Jun 12 02:12:32 CEST 2015


On 06/11/2015 04:23 PM, Ron Adam wrote:
>
>
> On 06/11/2015 03:10 PM, Ethan Furman wrote:
>> On 06/11/2015 03:56 AM, Chris Angelico wrote:
>>
>>> while input("Spam? ") as spam:
>>>      print(globals())
>>>      break
>>>
>>> Spam? yes
>>> {... 'spam.0x7f2080260228': 'yes'...}
>>
>> Having names not leak from listcomps and genexps is a good thing.
>
> In a way this makes sense because you can think of them as a type of function literal.
>
>
>
>> Having names not leak from if/else or while is confusing and irritating:
>> there is no scope there, and at least 'while' should be similar to 'for'
>> which also does a name binding and does /not/ unset it at the end.
>
> Having a group of statement share a set of values is fairly easy to think about.

But that is not how Python works.  When you bind a name, that name stays until the scope is left (with one notable exception).

> Having them share some values at some times, and not others at other times is not so
>  easy to think about.

Which is why I would not have the psuedo-scope on any of them.  The only place where that currently happens is in a try/except clause, and that should remain the only exception.

--
~Ethan~


More information about the Python-ideas mailing list