Re: [Python-Dev] Symmetry arguments for API expansion

2018年3月12日 12:56:40 -0700

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:").
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to