Author robert_smallshire
Recipients Austin Bingham, christian.heimes, facundobatista, mark.dickinson, rhettinger, robert_smallshire, serhiy.storchaka, tim.peters
Date 2018-03-15.13:17:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1521119863.92.0.467229070634.issue26680@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-03-15 13:17:43robert_smallshiresetrecipients: + robert_smallshire, tim.peters, rhettinger, facundobatista, mark.dickinson, christian.heimes, serhiy.storchaka, Austin Bingham
2018-03-15 13:17:43robert_smallshiresetmessageid: <1521119863.92.0.467229070634.issue26680@psf.upfronthosting.co.za>
2018-03-15 13:17:43robert_smallshirelinkissue26680 messages
2018-03-15 13:17:43robert_smallshirecreate