From 5ab745fc51e159ead28b523414e52f0bcc1ef353 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 26 Feb 2022 00:53:27 +0100 Subject: bpo-46852: Remove the float.__set_format__() method (GH-31585) Remove the undocumented private float.__set_format__() method, previously known as float.__set_format__() in Python 3.7. Its docstring said: "You probably don't want to use this function. It exists mainly to be used in Python's test suite." --- Doc/library/unittest.mock.rst | 2 +- Doc/whatsnew/3.11.rst | 6 ++ Lib/test/test_float.py | 70 -------------------- Lib/unittest/mock.py | 2 +- .../2022-02-25-01-42-45.bpo-46852.nkRDvV.rst | 4 ++ Objects/clinic/floatobject.c.h | 69 +------------------- Objects/floatobject.c | 76 +--------------------- 7 files changed, 15 insertions(+), 214 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-02-25-01-42-45.bpo-46852.nkRDvV.rst diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 69f1035..dbea928 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -2165,7 +2165,7 @@ Magic methods that are supported but not setup by default in ``MagicMock`` are: * ``__reversed__`` and ``__missing__`` * ``__reduce__``, ``__reduce_ex__``, ``__getinitargs__``, ``__getnewargs__``, ``__getstate__`` and ``__setstate__`` -* ``__getformat__`` and ``__setformat__`` +* ``__getformat__`` diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 3f73bdf..8ebe1cb 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -574,6 +574,12 @@ Removed because it was not used and added by mistake in previous versions. (Contributed by Nikita Sobolev in :issue:`46483`.) +* Remove the undocumented private ``float.__set_format__()`` method, previously + known as ``float.__setformat__()`` in Python 3.7. Its docstring said: "You + probably don't want to use this function. It exists mainly to be used in + Python's test suite." + (Contributed by Victor Stinner in :issue:`46852`.) + Porting to Python 3.11 ====================== diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index f033736..3d2a21f 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -19,8 +19,6 @@ NAN = float("nan") have_getformat = hasattr(float, "__getformat__") requires_getformat = unittest.skipUnless(have_getformat, "requires __getformat__") -requires_setformat = unittest.skipUnless(hasattr(float, "__setformat__"), - "requires __setformat__") #locate file with float format test values test_dir = os.path.dirname(__file__) or os.curdir @@ -612,44 +610,6 @@ class GeneralFloatCases(unittest.TestCase): self.assertEqual(hash(value), object.__hash__(value)) -@requires_setformat -class FormatFunctionsTestCase(unittest.TestCase): - - def setUp(self): - self.save_formats = {'double':float.__getformat__('double'), - 'float':float.__getformat__('float')} - - def tearDown(self): - float.__setformat__('double', self.save_formats['double']) - float.__setformat__('float', self.save_formats['float']) - - def test_getformat(self): - self.assertIn(float.__getformat__('double'), - ['unknown', 'IEEE, big-endian', 'IEEE, little-endian']) - self.assertIn(float.__getformat__('float'), - ['unknown', 'IEEE, big-endian', 'IEEE, little-endian']) - self.assertRaises(ValueError, float.__getformat__, 'chicken') - self.assertRaises(TypeError, float.__getformat__, 1) - - def test_setformat(self): - for t in 'double', 'float': - float.__setformat__(t, 'unknown') - if self.save_formats[t] == 'IEEE, big-endian': - self.assertRaises(ValueError, float.__setformat__, - t, 'IEEE, little-endian') - elif self.save_formats[t] == 'IEEE, little-endian': - self.assertRaises(ValueError, float.__setformat__, - t, 'IEEE, big-endian') - else: - self.assertRaises(ValueError, float.__setformat__, - t, 'IEEE, big-endian') - self.assertRaises(ValueError, float.__setformat__, - t, 'IEEE, little-endian') - self.assertRaises(ValueError, float.__setformat__, - t, 'chicken') - self.assertRaises(ValueError, float.__setformat__, - 'chicken', 'unknown') - BE_DOUBLE_INF = b'\x7f\xf0\x00\x00\x00\x00\x00\x00' LE_DOUBLE_INF = bytes(reversed(BE_DOUBLE_INF)) BE_DOUBLE_NAN = b'\x7f\xf8\x00\x00\x00\x00\x00\x00' @@ -660,36 +620,6 @@ LE_FLOAT_INF = bytes(reversed(BE_FLOAT_INF)) BE_FLOAT_NAN = b'\x7f\xc0\x00\x00' LE_FLOAT_NAN = bytes(reversed(BE_FLOAT_NAN)) -# on non-IEEE platforms, attempting to unpack a bit pattern -# representing an infinity or a NaN should raise an exception. - -@requires_setformat -class UnknownFormatTestCase(unittest.TestCase): - def setUp(self): - self.save_formats = {'double':float.__getformat__('double'), - 'float':float.__getformat__('float')} - float.__setformat__('double', 'unknown') - float.__setformat__('float', 'unknown') - - def tearDown(self): - float.__setformat__('double', self.save_formats['double']) - float.__setformat__('float', self.save_formats['float']) - - def test_double_specials_dont_unpack(self): - for fmt, data in [('>d', BE_DOUBLE_INF), - ('>d', BE_DOUBLE_NAN), - ('f', BE_FLOAT_INF), - ('>f', BE_FLOAT_NAN), - ('