[Python-Dev] PEP 463: Exception-catching expressions
ethan at stoneleaf.us
Sun Feb 23 21:51:57 CET 2014
On 02/23/2014 11:26 AM, Thomas Wouters wrote:
> On Feb 23, 2014 7:52 PM, "Stefan Behnel" <stefan_ml at behnel.de <mailto:stefan_ml at behnel.de>> wrote:
>> Chris Angelico, 21.02.2014 04:15:
>> > Just as PEP 308 introduced a means of value-based conditions in an
>> > expression, this system allows exception-based conditions to be used
>> > as part of an expression.
>> > [...]
>> > This currently works::
>> > lst = [1, 2, None, 3]
>> > value = lst or "No value"
>> > The proposal adds this::
>> > lst = [1, 2]
>> > value = lst except IndexError: "No value"
>> 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)
Well, that is certainly not what I would have expected.
I can also see how parentheses can help, but I still would like them optional.
More information about the Python-Dev