`struct.pack` with format `s` errors on `bytes`-like data
Đang mở
@serhiy-storchaka đang làm issue này rồi.
Từ ngày 14/4/2026.
extension-modules
type-bug
type-feature
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Đánh giá
Issue này chưa được đánh giá.