Robert Smallshire <r...@sixty-north.com> added the comment:

Serhiy, you asked for use cases, not uses. The former can exist without the 
latter.  Use cases for is_integer() include all existing uses of x == int(x), 
or other less obvious means of detecting integer values.

Folks try to use x.is_integer(), discover it fails if x is an int, and go in 
search of a replacement, which may well be x == int(x), which goes on to fail 
in more complex and awkward to handle ways with NaN or Inf.

I've seen is_integer() used in guard clauses for functions which accept numbers 
which require an integral value (Recall that explicit type checking is usually 
called out as unPythonic, and rightly so). The Python factorial is example of 
such a function which makes an equivalent check. StackOverflow is awash with 
folks using isinstance(x, int) where that is not what they actually mean. Many 
of these are the same use-case, but don't use is_integer().

I've also seen it used in cases where different algorithms are more optimal 
depending on whether the arguments are integral or not (imagine some 
combination of factorial() and gamma()).

I've seen it used in conversion from float to custom number types used to 
simulate the unusual number types in embedded hardware.

I'm not going to engage with this discussion further. It's already consumed too 
much of my time, left me with a somewhat negative view of how Python 
development proceeds, and a confused view of the values that are most important 
to the Python language.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue26680>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to