bpo-46852: Remove the float.__set_format__() method (GH-31585) · python/cpython@5ab745f · GitHub
Skip to content

Commit 5ab745f

Browse files
authored
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."
1 parent 4060111 commit 5ab745f

7 files changed

Lines changed: 15 additions & 214 deletions

File tree

Doc/library/unittest.mock.rst

Lines changed: 1 addition & 1 deletion

Doc/whatsnew/3.11.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,12 @@ Removed
574574
because it was not used and added by mistake in previous versions.
575575
(Contributed by Nikita Sobolev in :issue:`46483`.)
576576

577+
* Remove the undocumented private ``float.__set_format__()`` method, previously
578+
known as ``float.__setformat__()`` in Python 3.7. Its docstring said: "You
579+
probably don't want to use this function. It exists mainly to be used in
580+
Python's test suite."
581+
(Contributed by Victor Stinner in :issue:`46852`.)
582+
577583
Porting to Python 3.11
578584
======================
579585

Lib/test/test_float.py

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
have_getformat = hasattr(float, "__getformat__")
2020
requires_getformat = unittest.skipUnless(have_getformat,
2121
"requires __getformat__")
22-
requires_setformat = unittest.skipUnless(hasattr(float, "__setformat__"),
23-
"requires __setformat__")
2422

2523
#locate file with float format test values
2624
test_dir = os.path.dirname(__file__) or os.curdir
@@ -612,44 +610,6 @@ class F(float, H):
612610
self.assertEqual(hash(value), object.__hash__(value))
613611

614612

615-
@requires_setformat
616-
class FormatFunctionsTestCase(unittest.TestCase):
617-
618-
def setUp(self):
619-
self.save_formats = {'double':float.__getformat__('double'),
620-
'float':float.__getformat__('float')}
621-
622-
def tearDown(self):
623-
float.__setformat__('double', self.save_formats['double'])
624-
float.__setformat__('float', self.save_formats['float'])
625-
626-
def test_getformat(self):
627-
self.assertIn(float.__getformat__('double'),
628-
['unknown', 'IEEE, big-endian', 'IEEE, little-endian'])
629-
self.assertIn(float.__getformat__('float'),
630-
['unknown', 'IEEE, big-endian', 'IEEE, little-endian'])
631-
self.assertRaises(ValueError, float.__getformat__, 'chicken')
632-
self.assertRaises(TypeError, float.__getformat__, 1)
633-
634-
def test_setformat(self):
635-
for t in 'double', 'float':
636-
float.__setformat__(t, 'unknown')
637-
if self.save_formats[t] == 'IEEE, big-endian':
638-
self.assertRaises(ValueError, float.__setformat__,
639-
t, 'IEEE, little-endian')
640-
elif self.save_formats[t] == 'IEEE, little-endian':
641-
self.assertRaises(ValueError, float.__setformat__,
642-
t, 'IEEE, big-endian')
643-
else:
644-
self.assertRaises(ValueError, float.__setformat__,
645-
t, 'IEEE, big-endian')
646-
self.assertRaises(ValueError, float.__setformat__,
647-
t, 'IEEE, little-endian')
648-
self.assertRaises(ValueError, float.__setformat__,
649-
t, 'chicken')
650-
self.assertRaises(ValueError, float.__setformat__,
651-
'chicken', 'unknown')
652-
653613
BE_DOUBLE_INF = b'\x7f\xf0\x00\x00\x00\x00\x00\x00'
654614
LE_DOUBLE_INF = bytes(reversed(BE_DOUBLE_INF))
655615
BE_DOUBLE_NAN = b'\x7f\xf8\x00\x00\x00\x00\x00\x00'
@@ -660,36 +620,6 @@ def test_setformat(self):
660620
BE_FLOAT_NAN = b'\x7f\xc0\x00\x00'
661621
LE_FLOAT_NAN = bytes(reversed(BE_FLOAT_NAN))
662622

663-
# on non-IEEE platforms, attempting to unpack a bit pattern
664-
# representing an infinity or a NaN should raise an exception.
665-
666-
@requires_setformat
667-
class UnknownFormatTestCase(unittest.TestCase):
668-
def setUp(self):
669-
self.save_formats = {'double':float.__getformat__('double'),
670-
'float':float.__getformat__('float')}
671-
float.__setformat__('double', 'unknown')
672-
float.__setformat__('float', 'unknown')
673-
674-
def tearDown(self):
675-
float.__setformat__('double', self.save_formats['double'])
676-
float.__setformat__('float', self.save_formats['float'])
677-
678-
def test_double_specials_dont_unpack(self):
679-
for fmt, data in [('>d', BE_DOUBLE_INF),
680-
('>d', BE_DOUBLE_NAN),
681-
('<d', LE_DOUBLE_INF),
682-
('<d', LE_DOUBLE_NAN)]:
683-
self.assertRaises(ValueError, struct.unpack, fmt, data)
684-
685-
def test_float_specials_dont_unpack(self):
686-
for fmt, data in [('>f', BE_FLOAT_INF),
687-
('>f', BE_FLOAT_NAN),
688-
('<f', LE_FLOAT_INF),
689-
('<f', LE_FLOAT_NAN)]:
690-
self.assertRaises(ValueError, struct.unpack, fmt, data)
691-
692-
693623
# on an IEEE platform, all we guarantee is that bit patterns
694624
# representing infinities or NaNs do not raise an exception; all else
695625
# is accident (today).

Lib/unittest/mock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,7 @@ def _patch_stopall():
19431943
_non_defaults = {
19441944
'__get__', '__set__', '__delete__', '__reversed__', '__missing__',
19451945
'__reduce__', '__reduce_ex__', '__getinitargs__', '__getnewargs__',
1946-
'__getstate__', '__setstate__', '__getformat__', '__setformat__',
1946+
'__getstate__', '__setstate__', '__getformat__',
19471947
'__repr__', '__dir__', '__subclasses__', '__format__',
19481948
'__getnewargs_ex__',
19491949
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Remove the undocumented private ``float.__set_format__()`` method, previously
2+
known as ``float.__setformat__()`` in Python 3.7. Its docstring said: "You
3+
probably don't want to use this function. It exists mainly to be used in
4+
Python's test suite." Patch by Victor Stinner.

Objects/clinic/floatobject.c.h

Lines changed: 1 addition & 68 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/floatobject.c

Lines changed: 2 additions & 74 deletions

0 commit comments

Comments
 (0)