>>> import array
>>> a = array.array('e', [123])
>>> a[0] = 123456 # doesn't fit in _Float16 but fits in _Float32
Traceback (most recent call last):
File "<python-input-5>", line 1, in <module>
a[0] = 123456
~^^^
OverflowError: float too large to pack with e format
>>> a
array('e', [123.0])
>>> a[0] = 1e300 # doesn't fit neither in _Float32 nor in _Float16
>>> a
array('e', [inf])
I believe both examples should trigger overflows.
Bug report
Bug description:
Consider this:
That's happened because we use
PyArg_Parse()function with'f'format code to parse floats. Then in the second casePyFloat_Pack2()seen plain infinity and doesn't trigger overflow.I believe both examples should trigger overflows.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs