[Python-Dev] Deprecating float.is_integer()

Guido van Rossum guido at python.org
Wed Mar 21 14:59:47 EDT 2018


On Wed, Mar 21, 2018 at 11:14 AM, David Mertz <mertz at gnosis.cx> wrote:

> I've been using and teaching python for close to 20 years and I never
> noticed that x.is_integer() exists until this thread. I would say the "one
> obvious way" is less than obvious.
>
> On the other hand, `x == int(x)` is genuinely obvious... and it
> immediately suggests the probably better `math.isclose(x, int(x))` that is
> what you usually mean.
>

We can argue about this forever, but I don't think I would have come up
with that either when asked "how to test a float for being a whole number".
I would probably have tried "x%1 == 0" which is terrible. I like to have an
API that doesn't have the pitfalls of any of the "obvious" solutions that
numerically naive people would come up with, and x.is_integer() is it.
Let's keep it.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180321/eaa50c00/attachment.html>


More information about the Python-Dev mailing list