12.03.18 21:15, Guido van Rossum пише:
There's a reason why adding this to int feels right to me. In mypy we
treat int as a sub*type* of float, even though technically it isn't a
sub*class*.. The absence of an is_integer() method on int means that
this code has a bug that mypy doesn't catch:
def f(x: float):
"do something else"
What is the real use case of float.is_integer()?
I searched on GitHub and found only misuses of it like
(x/5).is_integer() (x % 5 == 0 would be more correct and clear) or
(x**0.5).is_integer() (returns wrong result for large ints and some
floats) in short examples. Some of these snippets look like book
examples, and they propagate bad practices (like "if a.is_integer() ==
Python-Dev mailing list