New submission from Wolfgang Maier: numbers.Rational defines __float__ like this:
def __float__(self): """float(self) = self.numerator / self.denominator It's important that this conversion use the integer's "true" division rather than casting one side to float before dividing so that ratios of huge integers convert without overflowing. """ return self.numerator / self.denominator This assumes that division of two Integral numbers returns a float, which the numbers ABC does not enforce in any way. IMO, the only logical assumption is that division of any two Integral or Rational numbers gives a Real, for which the ABC guarantees a __float__ method in turn. So I think Rational.__float__ should return float(self.numerator / self.denominator) ---------- components: Library (Lib) messages: 241270 nosy: wolma priority: normal severity: normal status: open title: numbers.Rational implements __float__ incorrectly type: behavior versions: Python 3.5 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue23975> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com