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

Stefan Behnel stefan_ml at behnel.de
Sun Feb 23 20:20:52 CET 2014

Stefan Behnel, 23.02.2014 19:51:
> Cython has typed
> assignments, so a straight forward idea would be to handle TypeErrors in
> assignments like this:
>     cdef str s
>     s = x except TypeError: str(x)

Similar code in Python would be this:

    from array import array
    x = array('i', [1,2,3])
    value = "123"

    x[0] = value except TypeError: int(value)

> However, I guess that would similarly counter the idea of exception
> handling in an *expression*, and the correct and non-ambiguous way to do
> this would be to spell out the try-except block.


More information about the Python-Dev mailing list