Message416969
Tim, the problem may well be simply due to the documentation of math.isfinite() being off here.
This is what we currently have:
https://docs.python.org/3/library/math.html#math.isfinite
===
math.isfinite(x)
Return True if x is neither an infinity nor a NaN, and False otherwise. (Note that 0.0 is considered finite.)
New in version 3.2.
===
If this were re-worded as follows (and corresponding changes were made to other such functions), everyone would know what the expectations and behavior are:
===
math.isfinite(x)
If `x` is a `float` instance, this evaluates to `True` if `x` is
neither a float infinity nor a NaN, and `False` otherwise.
If `x` is not a `float` instance, this is evaluates to
`math.isfinite(float(x))`.
New in version 3.2.
===
This would be an accurate defining description of the actual behavior. Note that, "thanks to PEP-484", this abbreviation would currently be ambiguous though:
===
math.isfinite(x)
If `x` is a float, this evaluates to `True` if `x` is
neither a float infinity nor a NaN, and `False` otherwise.
If `x` is not a float, this is evaluates to
`math.isfinite(float(x))`.
New in version 3.2.
===
("ambiguous" since "float" means different things as a static type and as a numbers class - and it is not clear what would be referred to here).
Changing/generalizing the behavior might potentially be an interesting other proposal, but I would argue that then one would want to change the behavior of quite a few other functions here as well, and all this should then perhaps go into some other `xmath` (or so) module - bit like it is with `cmath`.
However, since the Python philosophy is to not rely on bureaucracy to enforce contracts (as C++, Java, etc. do it), but instead to rely on people's ability to define their own contracts, making the math.isfinite() contract more accurate w.r.t. actual behavior in the CPython implementation via extra clarification looks like a good thing to do, no? |
|
Date |
User |
Action |
Args |
2022-04-08 10:09:13 | tfish2 | set | recipients:
+ tfish2, tim.peters, rhettinger, mark.dickinson, steven.daprano, docs@python, serhiy.storchaka, Nathaniel Manista |
2022-04-08 10:09:13 | tfish2 | set | messageid: <1649412553.17.0.986322711256.issue47121@roundup.psfhosted.org> |
2022-04-08 10:09:13 | tfish2 | link | issue47121 messages |
2022-04-08 10:09:13 | tfish2 | create | |
|