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.
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.
--
Steven
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/DVVKKI62UX5QTCDYZEQ4DJJ3N4UGMX6T/
Code of Conduct: http://python.org/psf/codeofconduct/