This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Remove the float.__set_format__() method
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: mark.dickinson, rhettinger, tim.peters, vstinner
Priority: normal Keywords: patch

Created on 2022-02-25 00:07 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 31558 merged vstinner, 2022-02-25 01:06
PR 31578 merged vstinner, 2022-02-25 14:26
PR 31581 merged vstinner, 2022-02-25 14:51
PR 31585 merged vstinner, 2022-02-25 15:18
PR 31592 closed vstinner, 2022-02-26 00:15
PR 31601 merged vstinner, 2022-02-26 23:08
Messages (17)
msg413943 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-25 00:07
It has been decided to require IEEE 754 to build Python 3.11:
https://mail.python.org/archives/list/python-dev@python.org/thread/J5FSP6J4EITPY5C2UJI7HSL2GQCTCUWN/

At Python startup, _PyFloat_InitState() checks the IEEE 754 format at runtime. It can be changed using float.__get_format__() and  float.__set_format__() methods.

These methods docstrings say that they only exist to test Python itself:

"You probably don't want to use this function. It exists mainly to be used in Python's test suite."

These methods are private and not documented.

I propose to remove them.

Once they will be removed, it will become possible to move the detection of the IEEE 754 format in the build step (./configure script) rather than doing the detection at runtime (slower). It would remove an "if" in _PyFloat_Pack4() and _PyFloat_Pack8(), and allow to specialize these functions for the detected format at build time. These functions are used by serialization formats: marshal, pickle and struct.
msg413946 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2022-02-25 00:40
I would not miss these methods.  Unless Mark says they are needed, +1 for removal.
msg413947 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-25 00:48
See also bpo-46656: "Remove the Py_NO_NAN macro: require NAN to build Python 3.11".
msg413948 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-25 00:54
Oh wait, I'm now confused by the method names. In Python 3.10, the correct names at:

* float.__getformat__() <= 4 underscores
* float.__set_format__() <= 5 underscores

It's even more confusing because the "set format" is only used in one place: test_float, and test_float uses... __setformat__() (4 underscores).

A typo a was introduced in Python 3.7 by:

commit b5c51d3dd95bbfde533655fb86ac0f96f771ba7b
Author: Serhiy Storchaka <storchaka@gmail.com>
Date:   Sat Mar 11 09:21:05 2017 +0200

    bpo-20185: Convert float object implementation to Argument Clinic. (#543)
    
    Based on patch by Vajrasky Kok.

Since Python 3.7, the 4 "set format" tests are simply skipped!

$ ./python -m test -v test_float
(...)
test_getformat (test.test_float.FormatFunctionsTestCase) ... skipped 'requires __setformat__'
test_setformat (test.test_float.FormatFunctionsTestCase) ... skipped 'requires __setformat__'
(...)
test_double_specials_dont_unpack (test.test_float.UnknownFormatTestCase) ... skipped 'requires __setformat__'
test_float_specials_dont_unpack (test.test_float.UnknownFormatTestCase) ... skipped 'requires __setformat__'
(...)


Moreover, unittest.mock supports mocking __setformat__() (4 underscores).
msg413949 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-25 01:06
I wrote GH-31558 to fix the typo in the method name.
msg413950 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-25 01:10
We can keep the float.__getformat__() method, it doesn't harm. I change the issue title to only propose to remove the float.__setformat__() method.
msg413953 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-25 02:05
New changeset 7d03c8be5af2f1559dbc35b775b3116dfd63cfb6 by Victor Stinner in branch 'main':
bpo-46852: Rename float.__set_format__() to float.__setformat__() (GH-31558)
https://github.com/python/cpython/commit/7d03c8be5af2f1559dbc35b775b3116dfd63cfb6
msg413997 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-25 14:47
New changeset 0848da19ce8ea037ab1cfc569778e94bf8e3b24a by Victor Stinner in branch '3.10':
bpo-46852: Rename float.__set_format__() to float.__setformat__() (GH-31558) (GH-31578)
https://github.com/python/cpython/commit/0848da19ce8ea037ab1cfc569778e94bf8e3b24a
msg414005 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-25 15:13
New changeset a549cd1fc55888e2e287714b25e2cb2251913909 by Victor Stinner in branch '3.9':
bpo-46852: Rename float.__set_format__() to float.__setformat__() (GH-31558) (GH-31581)
https://github.com/python/cpython/commit/a549cd1fc55888e2e287714b25e2cb2251913909
msg414011 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2022-02-25 15:58
I'd be happy to see `float.__setformat__` go, if it's not still needed for Python's test suite (which was its entire raison d'être). If no-one noticed the accidental misnaming, then it's pretty clear no-one's been using it.

I'd like to bet that there are at least a few people out there using float.__getformat__, despite that its docstring says "You probably don't want to use this function".

Maybe we could consider moving the information contained in __getformat__ to somewhere more accessible (e.g., a new field in sys.float_info)?
msg414018 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-25 16:49
Mark Dickinson:
> I'd be happy to see `float.__setformat__` go, if it's not still needed for Python's test suite (which was its entire raison d'être). If no-one noticed the accidental misnaming, then it's pretty clear no-one's been using it.

Nobody noticed the since Python 3.7 (released in June 2018). Well, even test_float didn't use it :-D (I just fixed the typo yesterday.) So I expect that no one uses it.

> I'd like to bet that there are at least a few people out there using float.__getformat__, despite that its docstring says "You probably don't want to use this function".

Yeah, I changed my mind and I prefer to leave it unchanged for now. It doesn't prevent me to optimize _PyFloat_Pack8().
msg414050 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-25 23:53
New changeset 5ab745fc51e159ead28b523414e52f0bcc1ef353 by Victor Stinner in branch 'main':
bpo-46852: Remove the float.__set_format__() method (GH-31585)
https://github.com/python/cpython/commit/5ab745fc51e159ead28b523414e52f0bcc1ef353
msg414131 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-27 00:12
New changeset 5a1c637ec6264790d3cfeef46815c62c32b510f3 by Victor Stinner in branch 'main':
bpo-46852: Restore test_getformat() test (GH-31601)
https://github.com/python/cpython/commit/5a1c637ec6264790d3cfeef46815c62c32b510f3
msg414150 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2022-02-27 13:22
Thanks, Victor. I think this can be closed now.
msg414152 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-27 13:49
I reopen the issue for the second part of my plan:

"Once they will be removed, it will become possible to move the detection of the IEEE 754 format in the build step (./configure script) rather than doing the detection at runtime (slower). It would remove an "if" in _PyFloat_Pack4() and _PyFloat_Pack8(), and allow to specialize these functions for the detected format at build time. These functions are used by serialization formats: marshal, pickle and struct."
msg414158 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2022-02-27 15:30
> I reopen the issue for the second part of my plan

Hmm. That sounds like it should be a separate issue, or at the least, this issue should be retitled. It's helpful to keep issue titles accurate.
msg414493 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-03-03 23:39
I created a follow-up issue: bpo-46917 "Require IEEE 754 floating point to build Python 3.11". I close this one: float.__set_format__() has been removed.
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 91008
2022-03-03 23:39:31vstinnersetstatus: open -> closed

resolution: fixed
messages: + msg414493
title: Remove the float.__setformat__() method -> Remove the float.__set_format__() method
2022-02-27 15:30:31mark.dickinsonsetmessages: + msg414158
2022-02-27 13:49:39vstinnersetstatus: closed -> open
resolution: fixed -> (no value)
messages: + msg414152
2022-02-27 13:22:15mark.dickinsonsetstatus: open -> closed
resolution: fixed
messages: + msg414150

stage: patch review -> resolved
2022-02-27 00:12:37vstinnersetmessages: + msg414131
2022-02-26 23:08:33vstinnersetpull_requests: + pull_request29724
2022-02-26 00:15:14vstinnersetpull_requests: + pull_request29715
2022-02-25 23:53:38vstinnersetmessages: + msg414050
2022-02-25 16:49:11vstinnersetmessages: + msg414018
2022-02-25 15:58:46mark.dickinsonsetmessages: + msg414011
2022-02-25 15:18:24vstinnersetpull_requests: + pull_request29708
2022-02-25 15:13:53vstinnersetmessages: + msg414005
2022-02-25 14:51:09vstinnersetpull_requests: + pull_request29704
2022-02-25 14:47:14vstinnersetmessages: + msg413997
2022-02-25 14:26:29vstinnersetpull_requests: + pull_request29700
2022-02-25 02:05:45vstinnersetmessages: + msg413953
2022-02-25 01:10:59vstinnersetmessages: + msg413950
title: Remove float.__get_format__() and float.__set_format__() -> Remove the float.__setformat__() method
2022-02-25 01:06:52vstinnersetmessages: + msg413949
2022-02-25 01:06:10vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request29680
2022-02-25 00:54:40vstinnersetmessages: + msg413948
2022-02-25 00:48:34vstinnersetmessages: + msg413947
2022-02-25 00:40:46rhettingersetnosy: + rhettinger, mark.dickinson, tim.peters
messages: + msg413946
2022-02-25 00:07:57vstinnercreate