Skip to content

Fix str subclass map keys in the Python fallback - #771

Open
SakayanagiYuna wants to merge 1 commit into
msgpack:mainfrom
SakayanagiYuna:fix/fallback-str-subclass-map-key
Open

SakayanagiYuna wants to merge 1 commit into
msgpack:mainfrom
SakayanagiYuna:fix/fallback-str-subclass-map-key

Conversation

@SakayanagiYuna

Copy link
Copy Markdown

msgpack.fallback.unpackb() raises TypeError: can't intern Key when
ext_hook returns a str subclass as a map key, even with
strict_map_key=False. The C extension accepts the same key.

The fallback passes the subclass to sys.intern(), which only accepts exact
str objects on CPython. The fix skips interning for subclasses, preserving
the key's type and identity.

Adds one regression test: it fails before the fix and passes afterward. It
also checks that strict_map_key=True still rejects subclass keys. The full
suites pass on Windows with CPython 3.14.7: 179 C-extension tests and 176 pure
Python tests.

Only intern exact str keys so decoding hooks can return str subclasses
when strict_map_key=False, matching the C extension.

Add a regression test for key identity and strict_map_key validation.

This branch has not been deployed

No deployments
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.

1 participant