Overflows happened silently in array.array setters for 'e', 'f' and 'Zf' format types
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 36k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug report
Bug description:
Consider this:
>>> import array
>>> a = array.array('e', [123])
>>> a[0] = 123456
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
a[0] = 123456
~^^^
OverflowError: float too large to pack with e format
>>> a = array.array('f', [123])
>>> a[0] = 1e70 # no OverflowError
>>> a
array('f', [inf])
>>> a = array.array('Zf', [123])
>>> a[0] = 1e70j # no OverflowError
>>> a
array('Zf', [infj])
>>> import struct
>>> struct.pack('f', 1e70)
Traceback (most recent call last):
File "<python-input-7>", line 1, in <module>
struct.pack('f', 1e70)
~~~~~~~~~~~^^^^^^^^^^^
OverflowError: float too large to pack with f format
>>> struct.pack('>Zf', 1e70j)
Traceback (most recent call last):
File "<python-input-13>", line 1, in <module>
struct.pack('>Zf', 1e70j)
~~~~~~~~~~~^^^^^^^^^^^^^^
OverflowError: float too large to pack with f format
(BTW, f_setitem() suffers from same issue as https://github.com/python/cpython/issues/156864.)
Maybe it's a feature and array() should behave differently wrt the struct module. In either case, this behavior looks inconsistent. If we consider cases for 'f'/'Zf' types being correct - we should clear exceptions also for 'e' type code.
See also struct/array issues (merged to this per @vstinner suggestion):
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-156869
- gh-156868
- gh-156916
- gh-156919
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con los setters de array.array para los formatos 'e', 'f' y 'Zf', y luego compara su comportamiento de overflow con struct.pack, tal como se muestra en el informe. Revisa los PRs enlazados y las issues relacionadas antes de decidir cuál es la consistencia prevista; se considera terminado cuando el comportamiento seleccionado está implementado y cubierto para estos tipos de formato.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- backend
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100