gh-84978: expose __float__ dunder method as as_float by skirpichev · Pull Request #110460 · python/cpython
This is a lightweight alternative for #26827 (an alternate constructor could be more discoverable option). Similar functions could be added for __complex__() and __int__() methods. But, probably, support of float subclasses in __float__() should be removed first (see #109311).
Of course, this is not an equivalent to PyFloat_AsDouble(), which tries to use __index__() dunder if there is no __float__() one. But maybe it could serve at least as a partial solution for the issue?
to decide:
- name: as_float vs float (c.f. index)?
📚 Documentation preview 📚: https://cpython-previews--110460.org.readthedocs.build/