[Python-Dev] PEP 463: Exception-catching expressions
ronaldoussoren at mac.com
Thu Feb 27 11:44:48 CET 2014
On 27 Feb 2014, at 11:09, Chris Angelico <rosuav at gmail.com> wrote:
> On Thu, Feb 27, 2014 at 7:44 PM, Ronald Oussoren <ronaldoussoren at mac.com> wrote:
>> What about (also mentioned in the PEP)?
>> value = (expr except Exception try default)
>> This seems to read nicely, although “try” is at a completely different position than it is in the equivalent try statement.
>> I like the general idea, but like Brett I don’t like using a colon here at all.
> I see your "although" clause to be quite a strong objection. In the
> statement form of an if, you have:
I’m not convinced that this is a strong objection. The order of keywords is different, but that doesn’t have to be problem.
> if cond: true_suite
> else: false_suite
> In the expression form, you have:
> true_expr if cond else false_expr
> Putting "try" followed by the default is confusing, because any
> exception raised in the default-expr will bubble up. Stealing any
> other keyword from the try/except block would make just as little
> expr except Exception finally default # "finally" implies something
> that always happens
> expr except Exception else default # "else" implies *no* exception
> expr except Exception try default # "try" indicates the initial expr,
> not the default
I didn’t parse the expression this way at all, but quite naturally parsed is as “use expr, and try using default if expr raises Exception” and not as a RTL expression.
> default except Exception try expr # breaks L->R evaluation order
> Left to right evaluation order is extremely important to me.
I agree with that, RTL evaluation would be pretty odd in Python.
> I don't
> know about anyone else, but since I'm the one championing the PEP,
> you're going to have to show me a *really* strong incentive to reword
> it to advocate something like the last one :) This is stated in the
> Using try and except leaves the notation "mentally ambiguous" as to
> which of the two outer expressions is which. It doesn't make perfect
> sense either way, and I expect a lot of people would be flicking back
> to the docs constantly to make sure they had it right.
Really? The evaluation order you mention in above didn’t make sense to me until I tried to make sense of it.
More information about the Python-Dev