[Python-ideas] If branch merging

Chris Angelico rosuav at gmail.com
Sun Jun 7 18:11:21 CEST 2015


On Mon, Jun 8, 2015 at 1:54 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On 8 June 2015 at 01:29, Chris Angelico <rosuav at gmail.com> wrote:
>> There's no concept of nested/limited scope here, although I'm sure
>> that this particular case could be turned into a subscope without
>> breaking anyone's code (I honestly cannot imagine there being ANY code
>> that depends on the name getting unset!), if Python ever grows support
>> for subscopes that aren't associated with nested functions.
>
> The unsetting of bound exceptions is also merely a language quirk
> introduced to cope with the implicit exception chaining introduced in
> PEP 3134. The circular reference from the traceback frame back to the
> bound exception caused a lot of uncollectable cycles that were
> resolved by automatically dropping the frame's reference to the bound
> exception.

Right. I know the reason for it, and it's a special case for
exceptions because of the traceback. (Though I'm not sure why
exception chaining causes this. Was that the first place where the
traceback - with its reference to locals - was made a part of the
exception object?) If Python had a concept of nested scopes within
functions, it'd make equal sense to have the "except X as e:" subscope
shadow, rather than overwriting and unsetting, the outer "e". Since
neither that nor the list comprehension is implemented with nested
scopes, I think it's safe to say that "if cond as e:" wouldn't be
either.

ChrisA


More information about the Python-ideas mailing list