Overflows happened silently in array.array setters for 'e', 'f' and 'Zf' format types
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit den array.array-Settern für die Formate 'e', 'f' und 'Zf', und vergleichen Sie dann deren Overflow-Verhalten mit struct.pack, wie im Bericht gezeigt. Prüfen Sie die verlinkten PRs und verwandten Issues, bevor Sie die beabsichtigte Konsistenz festlegen; abgeschlossen bedeutet, dass das ausgewählte Verhalten für diese Formattypen implementiert und abgedeckt ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100