Add `take_bytes([n])` to `bytearray` providing a zero-copy path to `bytes`

Have a prototype implementation that does that :slight_smile: (see: Add zero-copy conversion of `bytearray` to `bytes` by providing `__bytes__()` - #53 by cmaloney). Doing that means there is a new internal use of PyBytes_FromStringAndSize(NULL, len) + _PyBytes_Resize(); from the other thread the hope was to avoid that and only change bytearray’s internals once by going to PyBytesWriter once it was added.

1 Like