On Tue, Feb 18, 2020 at 12:20 AM Soni L. <fakedme...@gmail.com> wrote: > > I looked at the PEP for None-aware operators and I really feel like they > miss one important detail of Python's data model: > > >>> {}[0] > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > KeyError: 0 > >>> [][0] > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > IndexError: list index out of range > > that is: missing items raise, rather than being None. as such I feel > like None-aware operators would encourage ppl to put None everywhere, > which from what I can tell, goes completely against Python's data model. > > however, exception-aware operators could be a potential alternative that: > > 1. works with existing code (no need to go shoving None everywhere) > 2. works in lambdas > 3. ends up being more useful? > > I don't know what the potential syntax would look like. perhaps > something along the lines of: > > exception-raising-expression ?: value-if-exception-raised > > or: > > exception-raising-expression ? (IndexError, KeyError, Etc) : > value-if-exception-raised > > but, thoughts?
See PEP 463 and the many MANY posts about it. ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/TP3JXRDZLHQGJODITZAMORJUUPQW6P5G/ Code of Conduct: http://python.org/psf/codeofconduct/