[Python-ideas] except expression

Chris Angelico rosuav at gmail.com
Tue Feb 18 01:01:22 CET 2014


On Tue, Feb 18, 2014 at 9:45 AM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>> On Mon, Feb 17, 2014 at 08:52:41AM +1100, Chris Angelico wrote:
>>
>>> Should the default clause have an inner scope in which the
>>> name exists, shadowing anything of the same name elsewhere? Should it
>>> behave
>>> the same way the statement try/except does, and unbind the name?
>
>
> We could sidestep the whole problem by not allowing
> an 'as' clause at all. I don't think it would be
> unreasonable to require the use of a try statement
> if you want to do anything that fancy.

I'd accept that if and only if it makes a huge difference to the
implementability of the proposal. Conceptually, it's easy to say
"inner scope". If it turns out that it's really REALLY hard to do
that, then rejecting 'as' could be a fall-back. But I'd really rather
keep it.



>> The inner scope does seem to demand a function call, though.
>
> A function call isn't *required* to achieve the effect
> of an inner scope, as far as I know. It's just that
> implementing an inner scope for list comprehensions
> without it would have required extensive changes to
> the way the bytecode compiler currently works, and
> using a function was easier.

Interesting. I'll reword that section a bit, then. It may be that
adding another use-case for inner scopes will make them more worth
implementing, and then everything (comprehensions, except statements,
and except expressions) can use them.

It might also be worth using an inner scope for a 'with' statement,
too. Every block statement that uses 'as' could introduce a sub-scope.
But that is *definitely* outside the, uh, scope of this PEP.

ChrisA


More information about the Python-ideas mailing list