Support __buffer__ objects in widget comm buffers#8283
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
__buffer__ objects in widget comm buffers
mscolnick
previously approved these changes
Feb 12, 2026
kylebarron
reviewed
Feb 12, 2026
| DataType = Optional[dict[str, Any]] | ||
| MetadataType = Optional[dict[str, Any]] | ||
| BufferType = Optional[list[bytes]] | ||
| Buffer = bytes | memoryview | bytearray |
There was a problem hiding this comment.
Why not use collections.abc.Buffer? or to support multiple Python versions: https://github.com/developmentseed/obspec/blob/6c74dc0e10bff82c08c530af37dca96cf25c39fe/src/obspec/_put.py#L17-L20
kylebarron
reviewed
Feb 12, 2026
|
|
||
|
|
||
| def _ensure_bytes(buf: object) -> bytes: | ||
| """Coerce a buffer to plain ``bytes`` for msgspec serialization. |
There was a problem hiding this comment.
Seems like that's the core issue, right? msgspec should handle buffers
Collaborator
Author
There was a problem hiding this comment.
Yeah exactly, we need upstream support but need some compatibility now.
Libraries like obstore expose a `Bytes` type that implements Python's buffer protocol but isn't a subclass of `bytes`, `memoryview`, or `bytearray`. When these objects ended up in widget comm buffers (e.g. from lonboard map tiles), msgspec didn't recognise them as native binary types and fell through to `enc_hook`, which produced invalid output instead of base64. This adds `_ensure_bytes()` in the comm layer to coerce any buffer-protocol object to plain `bytes` before building model messages.
a8b352f to
0ad1923
Compare
mscolnick
approved these changes
Feb 13, 2026
LiquidGunay
pushed a commit
to LiquidGunay/marimo
that referenced
this pull request
Feb 21, 2026
Libraries like obstore expose a `Bytes` type that implements Python's buffer protocol but isn't a subclass of `bytes`, `memoryview`, or `bytearray`. When these objects ended up in widget comm buffers (e.g. from lonboard map tiles), msgspec didn't recognise them as native binary types and fell through to `enc_hook`, which produced invalid output instead of base64. This adds `_ensure_bytes()` in the comm layer to coerce any buffer-protocol object to plain `bytes` before building model messages. Needed to support raster tiles in `lonboard`: <img src="https://github.com/user-attachments/assets/0652f406-779d-4db5-bca9-03dd315301a7" />
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Libraries like obstore expose a
Bytestype that implements Python's buffer protocol but isn't a subclass ofbytes,memoryview, orbytearray. When these objects ended up in widget comm buffers (e.g. from lonboard map tiles), msgspec didn't recognise them as native binary types and fell through toenc_hook, which produced invalid output instead of base64.This adds
_ensure_bytes()in the comm layer to coerce any buffer-protocol object to plainbytesbefore building model messages.Needed to support raster tiles in

lonboard: