Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-85989: deprecate float.__getformat__() class method#146400
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
534939eaaf2b0a907bfb1a8cbdbfe38e3083a4c818b93f48c04356f768a32649fe8a2227d31f2291401b67fc46ee4d5f183a0136eec185316dec973d33031740f9873a7f9a1a1389d582c55ab2File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -532,10 +532,44 @@ def dec(*args, **kwargs): | ||
| # for a discussion of this number. | ||
| SOCK_MAX_SIZE = 16 * 1024 * 1024 + 1 | ||
| # This helper exists for alternative Python implementations, that use | ||
| # the CPython test suite. | ||
| def _have_ieee_doubles(): | ||
skirpichev marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if sys.implementation.name == 'cpython': | ||
| return True | ||
| import math | ||
| import struct | ||
| # Check parameters for encoding of floats; a quick exit | ||
| # if they aren't same as for IEC 60559 doubles. Check | ||
| # also that subnormals are present. | ||
| if (struct.calcsize('d') != 8 | ||
| or sys.float_info.radix != 2 | ||
| or sys.float_info.mant_dig != 53 | ||
| or sys.float_info.dig != 15 | ||
| or sys.float_info.min_exp != -1021 | ||
| or sys.float_info.min_10_exp != -307 | ||
| or sys.float_info.max_exp != 1024 | ||
| or sys.float_info.max_10_exp != 308 | ||
| or not math.issubnormal(math.nextafter(0, 1))): | ||
| return False | ||
| # We attempt to determine if this machine is using IEC | ||
| # floating-point formats by peering at the bits of some | ||
| # carefully chosen value. Assume that integer and | ||
| # floating-point types have same endianness. | ||
| d = 9006104071832581.0 | ||
| d_be_bytes = b"\x43\x3f\xff\x01\x02\x03\x04\x05" | ||
| d_packed = struct.pack('d', d) | ||
| if sys.byteorder == 'little': | ||
| return d_packed == bytes(reversed(d_be_bytes)) | ||
| return d_packed == d_be_bytes | ||
| HAVE_IEEE_754 = _have_ieee_doubles() | ||
| # decorator for skipping tests on non-IEEE 754 platforms | ||
| requires_IEEE_754 = unittest.skipUnless( | ||
| float.__getformat__("double").startswith("IEEE"), | ||
| HAVE_IEEE_754, | ||
| "test requires IEEE 754 doubles") | ||
| del HAVE_IEEE_754 | ||
| # detect evidence of double-rounding: | ||
| x, y = 1e16, 2.9999 # use temporary values to defeat peephole optimizer | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -486,8 +486,7 @@ def test_builtin__qualname__(self): | ||
| # builtin classmethod: | ||
| self.assertEqual(dict.fromkeys.__qualname__, 'dict.fromkeys') | ||
| self.assertEqual(float.__getformat__.__qualname__, | ||
| 'float.__getformat__') | ||
| self.assertEqual(int.from_bytes.__qualname__, 'int.from_bytes') | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the replacement also be a dunder method? MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). | ||
| # builtin staticmethod: | ||
| self.assertEqual(str.maketrans.__qualname__, 'str.maketrans') | ||
| @@ -509,7 +508,7 @@ def test_builtin__self__(self): | ||
| # builtin classmethod: | ||
| self.assertIs(dict.fromkeys.__self__, dict) | ||
| self.assertIs(float.__getformat__.__self__, float) | ||
skirpichev marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| self.assertIs(int.from_bytes.__self__, int) | ||
| # builtin staticmethod: | ||
| self.assertIsNone(str.maketrans.__self__) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| The ``__getformat__()`` class method of the :class:`float` is deprecated. On | ||
| CPython, ``float.__getformat__()`` always return a string, prefixed with | ||
| ``"IEEE"``: to build CPython, you need support for IEEE 754 floating-point | ||
| numbers since Python 3.11. Patch by Sergey B Kirpichev. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.