This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients Nofar Schnider, gvanrossum, mark.dickinson, njs, rhettinger, serhiy.storchaka, tim.peters
Date 2018-03-15.18:02:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>

> [...] what would _you_ like to see done here?

Given that float.as_integer_ratio and Decimal.as_integer_ratio already exist, and that I don't have a working time machine right now, I'm in favour of adding int.as_integer_ratio purely for duck-typing reasons: I want to be able to use an int where a float is expected, and I _have_ encountered code in the past where I have to think too hard about what precise types are being used, and where that thinking seems as though it shouldn't be necessary. For the same reason, I'd support as_integer_ratio on the Fraction type. I don't really care whether it gets there via the Rational ABC or not. Adding as_integer_ratio to Rational as an @abstractmethod _does_ seem a step too far (because now anyone who registers a type with numbers.Integral or numbers.Rational has to implement as_integer_ratio), but my understanding is that that's not what's being proposed.

It doesn't bother me that the NumPy integer types won't support as_integer_ratio immediately (or possibly ever). The floating-point types don't either (except np.float64, which only has it because it inherits directly from Python's float), and it's hard to see how as_integer_ratio could be useful for a NumPy float32 array (for example), given that the returned numerator and denominator could exceed the bounds of any of the fixed-width NumPy integer types. I write a lot of NumPy-using code, but the world in which I do so rarely meets the world where I care about correct rounding, fractions, counting ulps error, etc. I haven't missed float32.as_integer_ratio or float16.as_integer_ratio yet.

If we're worried about NumPy compatibility, it might be interesting to get Nathaniel Smith's opinion.
Date User Action Args
2018-03-15 18:02:39mark.dickinsonsetrecipients: + mark.dickinson, gvanrossum, tim.peters, rhettinger, njs, serhiy.storchaka, Nofar Schnider
2018-03-15 18:02:39mark.dickinsonsetmessageid: <>
2018-03-15 18:02:39mark.dickinsonlinkissue33073 messages
2018-03-15 18:02:39mark.dickinsoncreate