|
msg413943 - (view) |
Author: STINNER Victor (vstinner) *  |
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) *  |
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) *  |
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) *  |
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) *  |
Date: 2022-02-25 01:06 |
I wrote GH-31558 to fix the typo in the method name.
|
|
msg413950 - (view) |
Author: STINNER Victor (vstinner) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
Date: 2022-02-27 13:22 |
Thanks, Victor. I think this can be closed now.
|
|
msg414152 - (view) |
Author: STINNER Victor (vstinner) *  |
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) *  |
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) *  |
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.
|