Skip to content

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

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

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

Conversation

@skirpichev
Copy link
Copy Markdown
Member

@skirpichev skirpichev commented Mar 25, 2026

Comment thread Lib/test/support/__init__.py Outdated
Comment thread Doc/deprecations/pending-removal-in-3.20.rst Outdated
@skirpichev skirpichev requested a review from AA-Turner as a code owner March 25, 2026 07:09
@skirpichev skirpichev requested a review from vstinner March 27, 2026 02:03
Comment thread Lib/test/support/__init__.py
@skirpichev
Copy link
Copy Markdown
Member Author

CC @serhiy-storchaka

Comment thread Doc/deprecations/pending-removal-in-3.20.rst Outdated
Comment thread Lib/test/support/__init__.py
Comment thread Lib/test/test_float.py
Comment thread Lib/test/test_funcattrs.py
vstinner
vstinner previously approved these changes Apr 1, 2026
Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@skirpichev
Copy link
Copy Markdown
Member Author

@vstinner, please don't merge. I would appreciate a second review.

@serhiy-storchaka
Copy link
Copy Markdown
Member

in general, I like removing private, unsystematic, undocumented methods which only serve internal debugging purpose. There some things in bytearray and set. But first we need to look at their history and ask authors who added them. Do they still need them? I think that special testing module would be better place for such things.

@skirpichev
Copy link
Copy Markdown
Member Author

But first we need to look at their history and ask authors who added them. Do they still need them?

The __getformat__() class method, together with removed __setformat__() was added by ba283e2. CC @mwhudson

I think that special testing module would be better place for such things.

This private API now is helpful only for alternative implementations, which run the CPython test suite. I don't see how a special testing module would help here.

See #145633 (comment) for some usage examples.

@mwhudson
Copy link
Copy Markdown

But first we need to look at their history and ask authors who added them. Do they still need them?

The __getformat__() class method, together with removed __setformat__() was added by ba283e2. CC @mwhudson

Oh dear me that was nearly 21 years ago! Unsurprisingly the details have faded a bit but I'm pretty sure this was around making struct.{pack,unpack} work with NaNs and infs and such. If Python requires IEEE 754 to build then I think it can all be regarded as historical fluff and deprecated then deleted.

@skirpichev
Copy link
Copy Markdown
Member Author

If Python requires IEEE 754 to build then I think it can all be regarded as historical fluff and deprecated then deleted.

The problem is that the CPython test suite used in alternative implementations, like PyPy. In principle they may not require IEEE-compatible formats for floats.

That's why @mdickinson suggested to keep requires_IEEE_754 decorator. Which, in turn, needs something to check that this requirement is satisfied. New helper does same checks as before, if ctypes module is available.

Comment thread Lib/test/support/__init__.py Outdated
Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Would not be better to first add a field to sys.version_info? Then, few versions late, we can deprecate float.__getformat__().

Comment thread Lib/test/test_float.py Outdated
@skirpichev
Copy link
Copy Markdown
Member Author

Would not be better to first add a field to sys.version_info?

@serhiy-storchaka, not sure I get this part of you proposal. Could you elaborate?

Comment thread Lib/test/pythoninfo.py

def collect_builtins(info_add):
info_add('builtins.float.float_format', float.__getformat__("float"))
info_add('builtins.float.double_format', float.__getformat__("double"))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you modify collect_support() to log support.HAVE_IEEE_754?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Why do you think this make sense? For CPython builds this flag is True unconditionally.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To help debugging issues if HAVE_IEEE_754 is false for whatever reasons.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I would consider case when sys.implementation.name != 'cpython' for CPython as very unlikely scenario.

@vstinner
Copy link
Copy Markdown
Member

Would not be better to first add a field to sys.version_info?

Do you mean sys.float_info? Which members do you want to add?

@skirpichev skirpichev requested a review from vstinner April 17, 2026 11:58
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.

4 participants