This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients mark.dickinson, serhiy.storchaka
Date 2016-05-11.08:05:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1462953924.63.0.419748419084.issue26983@psf.upfronthosting.co.za>
In-reply-to
Content
+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).
History
Date User Action Args
2016-05-11 08:05:24mark.dickinsonsetrecipients: + mark.dickinson, serhiy.storchaka
2016-05-11 08:05:24mark.dickinsonsetmessageid: <1462953924.63.0.419748419084.issue26983@psf.upfronthosting.co.za>
2016-05-11 08:05:24mark.dickinsonlinkissue26983 messages
2016-05-11 08:05:24mark.dickinsoncreate