Skip to content

Commit a2ea6bf

Browse files
committed
gh-154568: Apply final review suggestions
1 parent 6a9ffe1 commit a2ea6bf

2 files changed

Lines changed: 7 additions & 23 deletions

File tree

Lib/test/test_array.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -244,26 +244,14 @@ def test_numbers(self):
244244
msg="{0!r} != {1!r}; testcase={2!r}".format(a, b, testcase))
245245

246246
def test_float16_endianness(self):
247-
# gh-154568: the slow-path decoder for IEEE_754_FLOAT16_LE/BE
248-
# compared mformat_code against the 32-bit float constant
249-
# (IEEE_754_FLOAT_LE) instead of the float16 one, so it always
250-
# decoded as big-endian regardless of what was requested.
251-
#
252-
# A real 'e'-typecode array only exercises the slow (converting)
253-
# path when the requested mformat disagrees with the *native*
254-
# float16 format, so which of LE/BE actually exercises the buggy
255-
# branch depends on the test machine's endianness, and the other
256-
# direction happens to come out "correct by coincidence" because
257-
# the bug unconditionally decodes as big-endian. Using a
258-
# typecode ('d') whose native mformat can never match
259-
# IEEE_754_FLOAT16_LE/BE forces the slow path deterministically
260-
# on any machine, so both directions are actually exercised.
261-
le_bytes = struct.pack('<e', 1.0)
262-
be_bytes = struct.pack('>e', 1.0)
247+
# gh-154568: array_reconstructor() slow-path decoder for
248+
# IEEE_754_FLOAT16_LE ignored the encoding.
249+
le_bytes = struct.pack('<e', 1.5)
250+
be_bytes = struct.pack('>e', 1.5)
263251
b_le = array_reconstructor(array.array, 'd', IEEE_754_FLOAT16_LE, le_bytes)
264252
b_be = array_reconstructor(array.array, 'd', IEEE_754_FLOAT16_BE, be_bytes)
265-
self.assertEqual(b_le.tolist(), [1.0])
266-
self.assertEqual(b_be.tolist(), [1.0])
253+
self.assertEqual(b_le.tolist(), [1.5])
254+
self.assertEqual(b_be.tolist(), [1.5])
267255

268256
def test_unicode(self):
269257
teststr = "Bonne Journ\xe9e \U0002030a\U00020347"
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
Fix ``array._array_reconstructor`` (used internally for unpickling
2-
:class:`array.array`) ignoring the requested byte order and always
3-
decoded as big-endian. This could silently produce wrong values when
4-
unpickling a half precision float array on a machine with different
5-
native endianness than the one that pickled it.
1+
Fix :mod:`array` unpickling of little-endian float16.

0 commit comments

Comments
 (0)