[Python-Dev] What's the status of PEP 505: None-aware operators? (original) (raw)

Barry Warsaw barry at python.org
Wed Nov 29 13:02:58 EST 2017


On Nov 29, 2017, at 12:40, David Mertz <mertz at gnosis.cx> wrote:

I think some syntax could be possible to only "catch" some exceptions and let others propagate. Maybe:

val = name.strip()[4:].upper() except (AttributeError, KeyError): -1 I don't really like throwing a colon in an expression though. Perhaps some other word or symbol could work instead. How does this read: val = name.strip()[4:].upper() except -1 in (AttributeError, KeyError)

I don’t know whether I like any of this but I think a more natural spelling would be:

val = name.strip()[4:].upper() except (AttributeError, KeyError) as -1

which could devolve into:

val = name.strip()[4:].upper() except KeyError as -1

or:

val = name.strip()[4:].upper() except KeyError # Implicit as None

I would not add any spelling for an explicit bare-except equivalent. You would have to write:

val = name.strip()[4:].upper() except Exception as -1

Cheers, -Barry

-------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: Message signed with OpenPGP URL: <http://mail.python.org/pipermail/python-dev/attachments/20171129/b59046e8/attachment.sig>



More information about the Python-Dev mailing list