Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/test/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,12 @@ class HalfFloatTest(FPTest, unittest.TestCase):
typecode = 'e'
minitemsize = 2

def test_overflows(self):
# Overflows half-float type:
self.assertRaises(OverflowError, array.array, self.typecode, [123456])
# Overflows also float type:
self.assertRaises(OverflowError, array.array, self.typecode, [1e300])

class FloatTest(FPTest, unittest.TestCase):
typecode = 'f'
minitemsize = 4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:func:`array.array` setter now correctly detects overflows for the ``'e'``
type code. Patch by Sergey B Kirpichev.
4 changes: 2 additions & 2 deletions Modules/arraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,8 @@ e_getitem(arrayobject *ap, Py_ssize_t i)
static int
e_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
float x;
if (!PyArg_Parse(v, "f;array item must be float", &x)) {
double x;
if (!PyArg_Parse(v, "d;array item must be float", &x)) {
return -1;
}

Expand Down
Loading