Message265295
+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). |
|
Date |
User |
Action |
Args |
2016-05-11 08:05:24 | mark.dickinson | set | recipients:
+ mark.dickinson, serhiy.storchaka |
2016-05-11 08:05:24 | mark.dickinson | set | messageid: <1462953924.63.0.419748419084.issue26983@psf.upfronthosting.co.za> |
2016-05-11 08:05:24 | mark.dickinson | link | issue26983 messages |
2016-05-11 08:05:24 | mark.dickinson | create | |
|