[Python-Dev] Symmetry arguments for API expansion

Serhiy Storchaka storchaka at gmail.com
Mon Mar 12 15:53:51 EDT 2018


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):
>      if x.is_integer():
>          "do something"
>      else:
>          "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() == 
True:").



More information about the Python-Dev mailing list

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant