Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions msgpack/fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,10 @@ def pack_ext_type(self, typecode, data):
self._buffer.write(b"\xc9" + struct.pack(">I", L))
self._buffer.write(struct.pack("B", typecode))
self._buffer.write(data)
if self._autoreset:
ret = self._buffer.getvalue()
self._buffer = BytesIO()
return ret
Comment on lines +864 to +867
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a regression test that asserts Packer().pack_ext_type(...) returns the packed bytes when autoreset is enabled, and that the internal buffer is cleared (e.g., a subsequent packer.pack(99) should not include the previously packed ext bytes). This would have caught the original bug and will prevent it from reappearing.

Copilot uses AI. Check for mistakes.
Comment on lines +864 to +867
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds autoreset handling for the pure-Python fallback Packer only. The default C-extension implementation (msgpack/_packer.pyx:pack_ext_type) still doesn’t return bytes or reset its internal buffer when autoreset is enabled, so msgpack.Packer().pack_ext_type(...) will remain broken in typical installs unless the Cython path is updated too.

Copilot uses AI. Check for mistakes.

def _pack_array_header(self, n):
if n <= 0x0F:
Expand Down
Loading