Re: [Python-ideas] [Python-Dev] What's the status of PEP 505: None-aware operators?

True enough. I remember the prior discussion, but didn't look up the PEP number. I know it's hard to revisit these ideas, but occasionally it works, especially if a nicer spelling is found (Barry proposed some a bit different than my ideas) On Nov 29, 2017 9:55 AM, "Eric V. Smith" <eric@trueblade.com> wrote: On Nov 29, 2017, at 12:40 PM, David Mertz <mertz@gnosis.cx> wrote: I like much of the thinking in Random's approach. But I still think None isn't quite special enough to warrant it's own syntax. However, his '(or None: name.strip()[4:].upper())' makes me realize that what is being asked in all the '?(', '?.', '?[' syntax ideas is a kind of ternary expression. Except the ternary isn't based on whether a predicate holds, but rather on whether an exception occurs (AttributeError, KeyError, TypeError). And the fallback in the ternary is always None rather than being general. I think we could generalize this to get something both more Pythonic and more flexible. E.g.: val = name.strip()[4:].upper() except None This would just be catching all errors, which is perhaps too broad. But it *would* allow a fallback other than None: val = name.strip()[4:].upper() except -1 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) Where the 'in' clause at the end would be optional, and default to 'Exception'. I'll note that what this idea DOES NOT get us is: val = timeout ?? local_timeout ?? global_timeout Those values that are "possibly None" don't raise exceptions, so they wouldn't apply to this syntax. See the rejected PEP 463 for Exception catching expressions. Eric. Yours, David... On Wed, Nov 29, 2017 at 9:03 AM, Random832 <random832@fastmail.com> wrote:
-- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th. _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/ eric%2Ba-python-dev%40trueblade.com
participants (1)
-
David Mertz