[Python-Dev] PEP 463: Exception-catching expressions
rosuav at gmail.com
Sun Feb 23 22:55:32 CET 2014
On Mon, Feb 24, 2014 at 6:26 AM, Thomas Wouters <thomas at python.org> wrote:
>> I see a risk of interfering with in-place assignment operators, e.g.
>> x /= y except ZeroDivisionError: 1
>> might not do what one could expect, because (as I assume) it would behave
>> differently from
>> x = x / y except ZeroDivisionError: 1
> Yes. Augmented assignment is still assignment, so a statement. The only way
> to parse that is as
> x /= (y except ZeroDivisionError: 1)
> and it'd be equivalent to
> x = x / (y except ZeroDivisionError: 1)
> (If the parentheses are mandatory that makes it easier to spot the
>> I think that falls under the "overly broad exception handling" issue. If
>> you want to include the assignment, you'll have to spell out the
>> block yourself. I find the difference in the two behaviours very
>> unfortunate, though.
Thomas's analysis is correct. It's not overly broad; in fact, what you
have is an overly _narrow_ exception handler, catching a
ZeroDivisionError from the evaluation of y only.
More information about the Python-Dev