Mark Dickinson added the comment:

True. Though having a subclass of float that overrides as_integer_ratio seems a 
fairly unlikely use-case. We could add a check for subclasses of float that the 
denominator is a power of 2 (using the usual trick: a positive integer n is a 
power of 2 if and only if `n & (n-1)` is zero) and raise a suitable error 
otherwise.

I doubt it's worth trying to support arbitrary return values from 
as_integer_ratio. Note that by overriding as_integer_ratio, you're breaking its 
"contract": the docs say

> Return a pair of integers, whose ratio is exactly equal to the original
> float and with a positive denominator.

and you've lost that "exactly equal". I think it's reasonably to get wrong 
results or an exception in that case.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26975>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to