Overflows happened silently in array.array setters for 'e', 'f' and 'Zf' format types
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con i setter di array.array per i formati 'e', 'f' e 'Zf', quindi confronta il loro comportamento in caso di overflow con struct.pack, come mostrato nel report. Esamina le PRs collegate e le issue correlate prima di decidere la coerenza prevista; il lavoro è completato quando il comportamento selezionato è implementato e coperto per questi tipi di formato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100