-
-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove the float.__set_format__() method #91008
Comments
It has been decided to require IEEE 754 to build Python 3.11: 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. |
I would not miss these methods. Unless Mark says they are needed, +1 for removal. |
See also bpo-46656: "Remove the Py_NO_NAN macro: require NAN to build Python 3.11". |
Oh wait, I'm now confused by the method names. In Python 3.10, the correct names at:
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 b5c51d3
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). |
I wrote #75739 to fix the typo in the method name. |
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. |
I'd be happy to see 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)? |
Mark Dickinson:
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.
Yeah, I changed my mind and I prefer to leave it unchanged for now. It doesn't prevent me to optimize _PyFloat_Pack8(). |
Thanks, Victor. I think this can be closed now. |
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." |
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. |
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. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: