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:").
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4