[issue40801] Expose PyFloat_ToDouble at Python level: operator.as_float?
Zachary Ware
report at bugs.python.org
Thu May 28 12:01:32 EDT 2020
Zachary Ware <zachary.ware at gmail.com> added the comment:
`operator` seems a slightly odd place for this. My naive expectation would be that `float(floatlike_obj)` should do what you want, but it seems that's not the case (too permissive of input types?). So then, what about an alternate constructor on the float object, `float.from_floatlike(obj)`? This could be implemented as effectively:
class float:
@classmethod
def from_floatlike(cls, obj):
return cls(PyFloat_FromDouble(PyFloat_AsDouble(obj)))
which would work to get an instance of any float subclass after a round-trip through a double. I have no idea whether that's actually useful, though :)
----------
nosy: +zach.ware
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40801>
_______________________________________
More information about the Python-bugs-list
mailing list