Skip to content

Fix serializing list subclasses with external storage - #1157

Open
adamchainz wants to merge 1 commit into
msgspec:mainfrom
adamchainz:list_subclasses
Open

Fix serializing list subclasses with external storage#1157
adamchainz wants to merge 1 commit into
msgspec:mainfrom
adamchainz:list_subclasses

Conversation

@adamchainz

Copy link
Copy Markdown

Fixes #1156.

The new ms_list_is_plain function checks whether a list subclass stores its items in the internal list storage, and if not, copies the items out through the sequence protocol before serializing. This ensures that list subclasses are not serialized to an empty array.

Fixes msgspec#1156.

The new `ms_list_is_plain` function checks whether a `list` subclass
stores its items in the internal list storage, and if not, copies the
items out through the sequence protocol before serializing. This ensures
that `list` subclasses are not serialized to an empty array.
@codspeed-hq

codspeed-hq Bot commented Aug 15, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 139 untouched benchmarks
⏩ 135 skipped benchmarks1


Comparing adamchainz:list_subclasses (52ca349) with main (f51f378)

Open in CodSpeed

Footnotes

  1. 135 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@provinzkraut provinzkraut left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think special casing lists here is the solution, and the current behaviour is documented.

I left a more detailed response here: #1156 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

list subclasses that store data elsewhere silently encode as []

2 participants