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

MRAB python at mrabarnett.plus.com
Sun Feb 23 02:11:45 CET 2014

On 2014-02-23 00:09, Chris Angelico wrote:
 > On Sun, Feb 23, 2014 at 11:00 AM, Thomas Wouters <thomas at python.org>
 > wrote:
 >> On Sat, Feb 22, 2014 at 2:08 AM, Thomas Wouters <thomas at python.org>
 >> wrote:
 >>> (FWIW, I have a working patch without tests that allows all of
 >>> these, I'll upload it tonight so people can play with it. Oh, and
 >>> FWIW, currently I'm +0 on the idea, -0 on the specific syntax.)
 >> http://bugs.python.org/issue20739 is the patch.
 > Thanks!
 > You make a comment about precedence. When I wrote that up, it was
 > basically just "that seems about right"; whether it's equal to
 > lambda, equal to if/else, above both, below both, or in between, is
 > free to be tweaked according to what makes sense. Nobody has to date
 > discussed the exact precedence order, so feel free to tweak it for
 > the benefit of implementation.
My feeling is that catching exceptions should have a lower precedence
than the other parts of an expression, but higher than comma, so:

A if C else B except E: D

would be parsed as:

(A if C else B) except E: D

I think that's because it's kind of replacing:

     _ = expr
except E:
     _ = D

with the try..except enclosing the expression.

More information about the Python-Dev mailing list