On Tue, Oct 19, 2021 at 05:09:42PM -0700, Michael Selik wrote:

> None and its ilk often conflate too many qualities. For example, is it
> missing because it doesn't exist, it never existed, or because we never
> received a value, despite knowing it must exist?

Does it matter if different functions have different semantic 
interpretations for None?


> The languages SAS and R
> support at least 27 varieties of NA, allowing un-tagged, and tagged with
> the letters A-Z to help someone create distinctions between different kinds
> of nothingness. IEEE-754 allows about 16 million possible NaNs, which I
> believe was intended to allow floating point instructions to pass error
> messages along.

Yes, and after something like 30-40 years of IEEE-754 supporting NAN 
payloads, the number of systems that actually use them can probably be 
counted on the fingers of one hand :-(

Ironically, one of those systems is R, which -- so I have been lead to 
believe -- uses distict NANs to represent those 27 tagged NA values.

Back in the 1980s, one of the earliest systems which supported IEEE-754 
maths was the Apple Numeric Toolkit. Apple's maths routines generated 
NANs with documented payloads for certain errors, e.g:

* NAN(1)  invalid sqrt
* NAN(2)  invalid addition such as INF + -INF
* NAN(34) invalid argument to inverse trig functions

In a complex computation, it was sometimes useful to see why a NAN was 
generated. Alas, when Apple moved their maths routines into hardware, 
the MC68881 coprocessor always generated NANs with payload 255, and that 
useful debugging information was lost.

30+ years later, and we cannot easily, reliably or portably use NAN 
payloads. Most people don't care. If we offerred them a dozen or a 
thousand distinct sentinels for all the various kinds of missing data, 
how many people would use them and how many would just stick to plain 
old None?


> If the motivation for this operator is chained lookups, how about adding a
> feature to the operator module, first? It seems natural to add a
> keyword-only argument to `attrgetter`, and it's a lighter touch than
> implementing a new operator. If use becomes widespread, that gives more
> weight to PEP 505.

I agree that this is a nice way forward, and a useful function in its 
own right. The only thing is that I would argue for a different colour 
of the bikeshed:

    def getattr_chain(obj, *attrs, default):
        # like obj.a.b.c.d
        # if any attribute is missing, 
        # raises if default is not given
        # otherwise returns default

getattr is far more commonly used than attrgetter.


-- 
Steve
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/AAHVRF7WXIZRUGBHOVBEB7NEZAYHHL26/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to