[issue40801] Expose PyFloat_ToDouble at Python level: operator.as_float?

Mark Dickinson report at bugs.python.org
Thu May 28 12:44:03 EDT 2020


Mark Dickinson <dickinsm at gmail.com> added the comment:

> `operator` seems a slightly odd place for this.

Yes, it's not ideal. It's by analogy with operator.index, which provides the equivalent duck-typing for integers, and calls __index__.  Similarly, operator.as_float is primarily there to call __float__, except that now that PyFloat_AsDouble also makes use of __index__, it'll call that, too.

My other thought was putting this in math, since it's what the math module is already doing implicitly to most inputs.

An alternative float constructor could work. Though we then run into the messy question of what it should do for float subclasses ...

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40801>
_______________________________________


More information about the Python-bugs-list mailing list