[Python-Dev] PEP 463: Exception-catching expressions

Antoine Pitrou solipsis at pitrou.net
Fri Feb 21 14:52:05 CET 2014

On Fri, 21 Feb 2014 14:15:59 +1100
Chris Angelico <rosuav at gmail.com> wrote:
> A number of functions and methods have parameters which will cause
> them to return a specified value instead of raising an exception.  The
> current system is ad-hoc and inconsistent, and requires that each
> function be individually written to have this functionality; not all
> support this.

While I sympathize with the motivation, I really don't like the end

>     lst = [1, 2]
>     value = lst[2] except IndexError: "No value"

is too much of a break from the usual stylistic conventions, and looks
like several statements were stuffed on a single line.

In other words, the gain in concision is counterbalanced by a loss in
readability, a compromise which doesn't fit in Python's overall design

(compare with "with", which solves actual readability issues due to the
distance between the "try" and the "finally" clause, and also promotes
better resource management)

So -0.5 from me.



More information about the Python-Dev mailing list