Wolfgang Maier added the comment:

Good point.

If the numbers ABC guaranteed numerator and denominator to be Integral numbers, 
this could be solved by:

return float(int(self.numerator) / int(self.denominator))

but since both could be Rationals again that does not seem to be an option 
either.
What could be done is trying to multiply out the numerator and denominator pair 
until both *are* Integrals, like:

num = self.numerator
den = self.denominator
while not (isinstance(num, Integral) and isinstance(den, Integral)):
    num = num.numerator * den.denominator
    den = den.numerator * num.denominator
return float(int(num) / int(den))

Clearly that's more complicated, but, more importantly, has the disadvantage 
that the loop will run forever if the final numerator or denominator is not 
registered correctly in the numeric tower.
So some kind of check for this situation would be required, but I do not have 
an idea right now what that should look like.

----------

_______________________________________
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

Reply via email to