[Python-Dev] Symmetry arguments for API expansion
Guido van Rossum
guido at python.org
Tue Mar 20 21:32:12 EDT 2018
No, the whole point of __index__ is that it refuses *all* floats --
otherwise people will do approximate computations that for their simple
test inputs give whole numbers, use them as sequence indices, and then find
their code broken only when the computation incurs some floating point
approximation. OTOH, is_integer() specifically asks whether a given real
value is a whole number so you can cast it to int() without rounding, etc.
On Tue, Mar 20, 2018 at 5:32 PM, Chris Barker <chris.barker at noaa.gov> wrote:
> It seems .as_integer_ratio() has been resolved.
> what about the original .is_integer() request? (Or did I miss that
> Anyway, it seems like __index__() should play a role here somehow... isn't
> that how you ask an object for the integer version of itself?
> Could float et al. add an __index__ method that would return a ValueError
> if the value was not an integer?
> Of course, as pointed out earlier in this thread, an "exact" integer is
> probably not what you want with a float anyway....
> On Tue, Mar 13, 2018 at 10:29 PM, Tim Peters <tim.peters at gmail.com> wrote:
>> >> An obvious way to extend it is for Fraction() to look for a special
>> >> method too, say "_as_integer_ratio()".
>> [Greg Ewing]
>> > Why not __as_integer_ratio__?
>> Because. at this point, that would be beating a dead horse ;-)
>> Python-Dev mailing list
>> Python-Dev at python.org
>> Unsubscribe: https://mail.python.org/mailman/options/python-dev/chris.
> Christopher Barker, Ph.D.
> Emergency Response Division
> NOAA/NOS/OR&R (206) 526-6959 voice
> 7600 Sand Point Way NE (206) 526-6329 fax
> Seattle, WA 98115 (206) 526-6317 main reception
> Chris.Barker at noaa.gov
> Python-Dev mailing list
> Python-Dev at python.org
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev