Skip to content

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

Open
skirpichev wants to merge 22 commits into
python:mainfrom
skirpichev:deprecate-__getformat__/145633
Open

gh-85989: deprecate float.__getformat__() class method#146400
skirpichev wants to merge 22 commits into
python:mainfrom
skirpichev:deprecate-__getformat__/145633

Conversation

@skirpichev

@skirpichevskirpichev commented Mar 25, 2026

Copy link
Copy Markdown
Member

Comment threadLib/test/support/__init__.py Outdated
Comment threadDoc/deprecations/pending-removal-in-3.20.rst Outdated
Comment threadLib/test/support/__init__.py
@skirpichev

Copy link
Copy Markdown
MemberAuthor

CC @serhiy-storchaka

Comment threadDoc/deprecations/pending-removal-in-3.20.rst Outdated
Comment threadLib/test/support/__init__.py
Comment threadLib/test/test_float.py
Comment threadLib/test/test_funcattrs.py
vstinner
vstinner previously approved these changes Apr 1, 2026

@vstinnervstinner left a comment

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.

LGTM

@skirpichev

Copy link
Copy Markdown
MemberAuthor

@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
MemberAuthor

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
MemberAuthor

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 @mdickinsonsuggested 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 threadLib/test/support/__init__.py Outdated

@serhiy-storchakaserhiy-storchaka left a comment

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.

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

Comment threadLib/test/test_float.py Outdated
@skirpichev
skirpichev deleted the deprecate-__getformat__/145633 branch May 4, 2026 15:25
@skirpichev
skirpichev restored the deprecate-__getformat__/145633 branch May 22, 2026 06:09
@skirpichevskirpichev changed the title gh-145633: deprecate float.__getformat__() class methodgh-85989: deprecate float.__getformat__() class methodMay 22, 2026
@skirpichevskirpichev reopened this May 22, 2026
@skirpichev

Copy link
Copy Markdown
MemberAuthor

then we will see if there are any serious ideas or arguments for or against the deprecation.

I think there aren't, no?

The sys.float_info also restricts it's scope to the float.h header. Lets not break it without good reasons. The C standard now have DBL_IS_IEC_60559 flag here, but it doesn't indicate something like conformance to the IEEE 754 double format. We can expose this, but I doubt it's a replacement for the current test.

@skirpichev

This comment was marked as outdated.

@skirpichev
skirpichev marked this pull request as draft August 3, 2026 05:41
@skirpichev
skirpichevforce-pushed the deprecate-__getformat__/145633 branch from ee74068 to 1389d58CompareAugust 3, 2026 23:10
@skirpichev
skirpichev deleted the deprecate-__getformat__/145633 branch August 3, 2026 23:37
@skirpichev
skirpichev restored the deprecate-__getformat__/145633 branch August 4, 2026 10:47
@skirpichevskirpichev reopened this Aug 4, 2026
@skirpichev

This comment has been minimized.

@skirpichev
skirpichev marked this pull request as ready for review August 4, 2026 11:41
self.assertEqual(dict.fromkeys.__qualname__, 'dict.fromkeys')
self.assertEqual(float.__getformat__.__qualname__,
'float.__getformat__')
self.assertEqual(int.from_bytes.__qualname__, 'int.from_bytes')

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.

Should the replacement also be a dunder method?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

There is nothing special for such case, except for a name.

Commentary says those should be class methods. I would guess not so many were available in v3.2, when the test was added (5b62942).

@vstinner

Copy link
Copy Markdown
Member

I don't think that you can simply deprecate (and later remove) float.__getformat__() with no replacement.

We need a replacement like sys.float_info.ieee_754 which would be used by @support.requires_IEEE_754.

See the SC decision: capi-workgroup/decisions#107 (comment).

Can you write a first PR to add sys.float_info.ieee_754?

@skirpichev

Copy link
Copy Markdown
MemberAuthor

I don't think that you can simply deprecate (and later remove) float.__getformat__() with no replacement.

__getformat__() was private, testing-only API. We have replacement for this: it's current PR with a helper for tests.

We need a replacement like sys.float_info.ieee_754 which would be used by @support.requires_IEEE_754. Can you write a first PR to add sys.float_info.ieee_754?

What this flag (?) will mean? Current testing helper has no clear meaning, it's a poor-mans replacement for __STDC_IEC_559__ define.

Sign up for freeto 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.

5 participants

@skirpichev@serhiy-storchaka@mwhudson@vstinner@merwok