[Python-ideas] except expression

Chris Angelico rosuav at gmail.com
Wed Feb 19 13:47:57 CET 2014


On Wed, Feb 19, 2014 at 11:17 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Right, unless Guido manages to pull another PEP 308 style "I have come
> up with a clever idea nobody else thought of, and likely only the BDFL
> could sell to anyone else", I think the colon based version Chris has
> written up in the PEP currently counts as "least bad of the
> alternatives proposed, and sufficiently tolerable to be judged better
> than the assortment of relatively ad hoc workarounds we have at the
> moment".
>
> That said, I did suggest using the function return type annotation
> marker as a possibility, and that's not currently listed in the PEP:
>
>     value = lst[2] except IndexError -> 'No value'

I missed that in the flurry. Have added it now.

> On an unrelated tangent (as I forget which part of the thread it came
> up in), having to switch from the compiler checked and code completion
> friendly 'obj.attr' to the more opaque (from an automated code
> analysis point of view) 'getattr(obj, "attr", None)' is another
> symptom of this current limitation that should be listed in the
> motivation section of the PEP.

Good point. Also added, though I put it into Rationale rather than Motivation.

ChrisA


More information about the Python-ideas mailing list