Skip to content

Remove "unknown_format" code path in PyFloat_Pack/Unpack*() #145633

Description

@skirpichev

This is a follow-up of the #91073. Proposal was briefly discussed in the referenced issue.

Now support for IEEE floating-point formats is a requirement and the configure script will fail, if it can't detect it. The only exception is some ARM platforms (this come from b08a53a):

cpython/configure.ac

Lines 6172 to 6180 in 149c465

[*arm*], [# Some ARM platforms use a mixed-endian representation for
# doubles. While Python doesn't currently have full support
# for these platforms (see e.g., issue 1762561), we can at
# least make sure that float <-> string conversions work.
# FLOAT_WORDS_BIGENDIAN doesn't actually detect this case,
# but if it's not big or little, then it must be this?
AC_DEFINE([DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754], [1],
[Define if C doubles are 64-bit IEEE 754 binary format,
stored in ARM mixed-endian order (byte order 45670123)])],

This is only case, when "unknown_format" code patch now could be triggered (BTW, we could detect this format in runtime and switch to yet another "just copy bytes" path). Should we keep this for an unsupported platform? IIRIC, such chips aren't supported even in Debian.

With "unknown_format" we also could drop code to detect endianness in runtime. I'm not sure about float.__getformat__ function. It's docstring says:

>>> help(float.__getformat__)
Help on built-in function __getformat__:

__getformat__(typestr, /) class method of builtins.float
    You probably don't want to use this function.

      typestr
        Must be 'double' or 'float'.

    It exists mainly to be used in Python's test suite.

    This function returns whichever of 'unknown', 'IEEE, big-endian' or 'IEEE,
    little-endian' best describes the format of floating-point numbers used by the
    C type named by typestr.

Probably, it could be treated as private and we should remove it in favor of using configure macros in tests. (__set_format__() method was removed without prior deprecation in 5ab745f). Edit: we could also leave this also as-is for alternative Python implementations, using CPython tests.

Linked PRs

Activity

  1. self-assigned this
    on Mar 8, 2026
  2. added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    buildThe build process and cross-build
    3.15bugs and security fixes
    on Mar 8, 2026
  3. skirpichev commented on Mar 8, 2026

    @skirpichev
    MemberAuthor

    CC @vstinner

    I tried but failed to remove this code.

    Do you remember why?

  4. added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    and removed
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    on Mar 8, 2026
  5. added a commit that references this issue on Mar 8, 2026
  6. corona10 commented on Mar 8, 2026

    @corona10
    Member
  7. removed their assignment
    on Mar 8, 2026
  8. vstinner commented on Mar 9, 2026

    @vstinner
    Member

    I tried but failed to remove this code.

    Do you remember why?

    I don't recall exactly. I think that I didn't understand well which platforms use "unknown format" and I was afraid of breaking anything.

  9. diegorusso commented on Mar 9, 2026

    @diegorusso
    Contributor

    I tried but failed to remove this code.

    Do you remember why?

    I don't recall exactly. I think that I didn't understand well which platforms use "unknown format" and I was afraid of breaking anything.

    Before merging, should we run the PR attaches via buildbot?

  10. 37 remaining items

  11. added 3 commits that reference this issue on Apr 16, 2026
  12. encukou commented on Apr 17, 2026

    @encukou
    Member

    I agree with dropping untested code, but I don't think we should prevent porting CPython to old (or future) non-IEEE platforms.

  13. skirpichev commented on Apr 17, 2026

    @skirpichev
    MemberAuthor

    The only way to do this is to revert choice made. Thread: https://mail.python.org/archives/list/python-dev@python.org/thread/J5FSP6J4EITPY5C2UJI7HSL2GQCTCUWN/

    I would say it will be a step backward.

  14. added 5 commits that reference this issue on Apr 25, 2026
  15. skirpichev commented on May 4, 2026

    @skirpichev
    MemberAuthor

    https://discuss.python.org/t/deprecate-float-getformat/107151 - discussion of __getformat__ removal.

    Lets close this. If someone wish to continue - it would be better to open a new issue.

  16. encukou commented on Jun 15, 2026

    @encukou
    Member

    I opened one in the C API WG repo: capi-workgroup/decisions#107

  17. added a commit that references this issue on Jul 10, 2026
  18. added a commit that references this issue on Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.15bugs and security fixesbuildThe build process and cross-buildinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-C-API

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions