Deprecate float.__getformat__()?

With Remove "unknown_format" code path in PyFloat_Pack/Unpack*() · Issue #145633 · python/cpython · GitHub, support for non-IEEE floating-point formats was removed. The remaining part is the semi-public float.__getformat__() class method, that now is redundant, as endianness could be tested by the sys.byteorder.

But despite this method is not useful for the CPython itself, it could be used for alternative implementations, using the CPython’s test suite. Here are some findings from top 15,000 PyPI’s projects, I think they confirm such usage pattern.

I propose deprecation of this method: gh-145633: deprecate float.__getformat__() class method by skirpichev · Pull Request #146400 · python/cpython · GitHub. New helper in the test.support module will replace it for tests. For alternative Python implementations this will make just same checks as before, but with the struct module.

Alternative would be some sys/sys.float_info option. But I don’t sure about it’s meaning. The former test in the float.__getformat__() just checked binary format for some chosen finite number to be as IEEE 754 double. But some tests in the CPython test suite, that depend on this, certainly assume more about runtime behavior of floating-point arithmetic, not just about binary format.

I proposed to expose the __STDC_IEC_559__ macro. That will means “full IEEE 754 compatibility”. Unfortunately, it seems it’s adoption by compilers/libc is provisional. On practice it doesn’t indicate conformance to the standard.

1 Like