Mark Dickinson added the comment:

+1 for the idea, and the patch LGTM.

I was initially a bit confused by the wording of the warning: presumably, we're 
not going to change Python to make returning an instance of a strict float 
subclass from __float__ illegal (I don't really see how that would be 
possible); we're just going to check the return type at the internal call sites 
to __float__ and raise if we get something other than an exact float. That is, 
I'd still expect this code to work on future versions of Python:

>>> class MyFloat(float): pass
... 
>>> class A:
...     def __float__(self): return MyFloat()
... 
>>> a = A()
>>> a.__float__()
0.0

But these would both become an error in Python 3.7 (say):

>>> float(a)
0.0
>>> math.sqrt(a)
0.0

Does that match your thinking?

We should probably add issues for checking and fixing other places that 
__float__ is used internally (like the math module).

----------

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

Reply via email to