Implement the bytearray builtin
JA
3d ago+5225+5225+0123456789012345678901234567890123456789-1088-1088-0123456789012345678901234567890123456789
Adds the bytearray builtin for mutable byte buffers inside the sandbox.
Supports construction, indexing and slice assignment, mutation methods, comparisons, formatting, concatenation,
repetition, += and *=, and shared bytes methods.
Aliases and iterator position survive snapshots.
Host conversion copies bytearrays as immutable bytes.
Memoryview support is tracked separately in #1228.
Validation:
- All 746 Monty fixtures pass; bytearray fixtures also pass against CPython.
- Bytearray, in-place container, snapshot compatibility, and serialization fingerprint tests pass.
- Search-bound callbacks that clear or grow a bytearray are covered across all seven search methods.
- Allocator-backed worker tests cover buffer growth, result conversion, translation, and concatenation under a 24 MiB limit.
Rejected allocations raiseMemoryErrorand leave the worker usable. - Timeout regressions cover
expandtabs, including a single large tab fill,translate, andmaketrans. - Clippy, Rust formatting, and fixture lint/format checks pass.
Strict private-item rustdoc checking still reports unrelated pre-existing broken links on main.
Remaining limitations:
- Memoryview and persistent exported buffers are deferred to #1228.
- Subscript deletion is unsupported; use slice assignment with an empty buffer instead.
- Constructors and mutation methods collect iterables synchronously; suspendable user iteration is unsupported.
- Error messages inherited from shared byte algorithms may refer to
bytesrather thanbytearray. - The
bytearraytype object crosses the host boundary as a representation string.
Part of the buffer prerequisites for #1201.