This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tfish2
Recipients Nathaniel Manista, docs@python, mark.dickinson, rhettinger, serhiy.storchaka, steven.daprano, tfish2, tim.peters
Date 2022-04-08.10:09:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1649412553.17.0.986322711256.issue47121@roundup.psfhosted.org>
In-reply-to
Content
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?
History
Date User Action Args
2022-04-08 10:09:13tfish2setrecipients: + tfish2, tim.peters, rhettinger, mark.dickinson, steven.daprano, docs@python, serhiy.storchaka, Nathaniel Manista
2022-04-08 10:09:13tfish2setmessageid: <1649412553.17.0.986322711256.issue47121@roundup.psfhosted.org>
2022-04-08 10:09:13tfish2linkissue47121 messages
2022-04-08 10:09:13tfish2create