`struct.pack` with format `s` errors on `bytes`-like data
Aperta
@serhiy-storchaka ci sta già lavorando.
Dal 14/4/2026.
extension-modules
type-bug
type-feature
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug report
Bug description:
When using struct.pack with format s, it works with bytes and bytearray. However other bytes-like data (such as memoryview) is not handled raising an error. Here is some sample code show this issue
import struct
b = b"abad"
struct. pack("4s", b) # Ok
struct. pack("4s", bytearray(b)) # Ok
struct. pack("4s", memoryview(b)) # Error
This code appears to contain the corresponding logic
CPython versions tested on:
3.14
Operating systems tested on:
macOS
Linked PRs
- gh-148565
- gh-149063
- gh-149072
- gh-152029
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.
Valutazione
Questa issue non è ancora stata valutata.