Implement the bytearray builtin

JA
3d ago
+5225-1088

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 raise MemoryError and leave the worker usable.
  • Timeout regressions cover expandtabs, including a single large tab fill, translate, and maketrans.
  • 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 bytes rather than bytearray.
  • The bytearray type object crosses the host boundary as a representation string.

Part of the buffer prerequisites for #1201.