On 2020-02-17 1:04 p.m., Steven D'Aprano wrote:
On Sun, Feb 16, 2020 at 10:07:13PM -0300, Soni L. 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:
[...]
> that is: missing items raise, rather than being None.

You are conflating two distinct cases. Your example `{}[0]` is the case
where the mapping is there, but the key is missing. You can already
solve that with `{}.get(0, default)`.

The None-aware use-case is *the mapping itself* is missing. In Python,
we don't have an `undefined` special value, like in Javascript, we use
None for the same purpose.

If the mapping itself is missing, then:

>>> foo[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'foo' is not defined

(or AttributeError sometimes)


Of course nobody is going to write the literal `None[key]`, but there
are plenty of cases where we need to distinguish between "there is no
dict" and "there is a dict, but it happens to be empty".


> 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.

Can you explain why you think that using None goes against Python's data
model? None is part of Python's data model; it is an object, like
everything else, and it has been used to represent "missing data" and
similar cases since Python 1.5 and older.

I feel like None-as-undefined goes against Python's data model because we have NameError, AttributeError, KeyError, IndexError, and probably others, and I feel like those do a better job of representing undefined.
_______________________________________________
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/AYHF4DHDQG4BLVXH3VX4YKXPZB4NF57P/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to