Skip to content

Fix typed deque serialization in the msgspec converter - #819

Merged
Tinche merged 3 commits into
python-attrs:mainfrom
HocVoNgThai:fix/msgspec-typed-deques
Nov 2, 2026
Merged

Tinche merged 3 commits into
python-attrs:mainfrom
HocVoNgThai:fix/msgspec-typed-deques

Conversation

@HocVoNgThai

Copy link
Copy Markdown
Contributor

The msgspec converter treats typed deques as passthrough sequences when their elements need no conversion. Msgspec cannot encode deques, so dumps() raises TypeError, including for deque fields inside attrs classes and dataclasses.

For example, a Queue dataclass with pending: deque[int] and value deque([1, 2]) currently fails to serialize. This change produces b'{"pending":[1,2]}', which loads back into the same queue.

Generate the normal iterable hook for deques, and resolve class field annotations before checking passthrough eligibility so postponed dataclass annotations work too. Add regressions for bare and typed deques, empty values, attrs/dataclass fields, dump hooks, and custom element hooks.

Closes #818

@codspeed

codspeed Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 note

ℹ️ 64 benchmarks have no flamegraph

The flamegraph wasn't generated: the symbols of the profiling trace could not be resolved, because no information about the language frames was collected.

See affected benchmarks

✅ 64 untouched benchmarks


Comparing HocVoNgThai:fix/msgspec-typed-deques (bd43263) with main (d043dbd)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (8a23a31) during the generation of this report, so d043dbd was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@Tinche

Tinche commented Nov 2, 2026

Copy link
Copy Markdown
Member

LGTM. Please add a link to the PR and issue. Would be good to ensure all preconf converters can handle deques but that may be an issue for a different PR.

@Tinche

Tinche commented Nov 2, 2026

Copy link
Copy Markdown
Member

Thanks!

@Tinche
Tinche merged commit e9239b7 into python-attrs:main Nov 2, 2026
15 checks passed
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.

msgspec converter cannot serialize typed deques

2 participants