Skip to content

gh-145633: deprecate float.__getformat__() class method#146400

Open
skirpichev wants to merge 4 commits intopython:mainfrom
skirpichev:deprecate-__getformat__/145633
Open

gh-145633: deprecate float.__getformat__() class method#146400
skirpichev wants to merge 4 commits intopython:mainfrom
skirpichev:deprecate-__getformat__/145633

Conversation

@skirpichev
Copy link
Member

@skirpichev skirpichev commented Mar 25, 2026

or not math.issubnormal(math.nextafter(0, 1))):
return False
try:
import ctypes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should move this check before the big if above, no?

Copy link
Member Author

@skirpichev skirpichev Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need at least some checks on implementations without the ctypes module. It seems, the struct module is available on WASI, I'll use it here.

That's why I think that the second option --- i.e. use iec_559 flag for format-only --- maybe is better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your current code starts with ctypes.sizeof(ctypes.c_double) != 8, but it only imports ctypes a few lines below. It cannot work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed that. Though, maybe it's better just to drop the size check.

(Contributed by Hugo van Kemenade and Stan Ulbrych in :gh:`76007`.)

* The ``__getformat__()`` class method of the :class:`float` is deprecated
and will be removed in Python 3.20.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should document the deprecation in What's New in Python 3.15.

What is the migration path for projects currently relying on __getformat__()? Do they have to copy/paste the big _have_ieee_doubles() function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the migration path for projects currently relying on getformat()? Do they have to copy/paste the big _have_ieee_doubles() function?

Primary goal is using the CPython's test suite. No changes needed.

But for the rest - yes.

@skirpichev skirpichev requested a review from AA-Turner as a code owner March 25, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants