Skip to content

fallback: pass object_pairs_hook a list of pairs - #744

Merged
methane merged 1 commit into
msgpack:mainfrom
youdie006:pairs-hook-list
Oct 2, 2026
Merged

methane merged 1 commit into
msgpack:mainfrom
youdie006:pairs-hook-list

Conversation

@youdie006

Copy link
Copy Markdown
Contributor

The pure-Python Unpacker passes object_pairs_hook a generator, while the C extension and the docstring give it a list of pairs. On PyPy or with MSGPACK_PUREPYTHON=1:

  • a hook that reads the pairs twice (for example to reject duplicate keys) returns {};
  • pairs[0] and len(pairs) raise TypeError;
  • a hook that ignores its argument leaves the map body unread, so the following objects are decoded from inside the map (ExtraData from unpackb).

This builds the list eagerly, keeping the strict_map_key check on each key; it is Finding 5 of #683. The check now runs whether or not the hook iterates, which matches the fallback's dict path and a hook like list. pytest test and MSGPACK_PUREPYTHON=1 pytest test pass; the new test fails on main under the fallback only.

Written with AI assistance (Claude); I have reviewed the change.

The pure-Python Unpacker passed a generator, so a hook that read the
pairs twice saw nothing the second time, indexing raised TypeError, and
a hook that ignored its argument left the map body unread. The C
extension and the docstring give a list.
@methane
methane merged commit 51428c4 into msgpack:main Oct 2, 2026
51 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.

2 participants