Repository navigation
Fix str subclass map keys in the Python fallback - #771
Open
SakayanagiYuna wants to merge 1 commit into
Open
SakayanagiYuna wants to merge 1 commit into
SakayanagiYuna wants to merge 1 commit into
Conversation
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
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.
msgpack.fallback.unpackb()raisesTypeError: can't intern Keywhenext_hookreturns astrsubclass as a map key, even withstrict_map_key=False. The C extension accepts the same key.The fallback passes the subclass to
sys.intern(), which only accepts exactstrobjects on CPython. The fix skips interning for subclasses, preservingthe key's type and identity.
Adds one regression test: it fails before the fix and passes afterward. It
also checks that
strict_map_key=Truestill rejects subclass keys. The fullsuites pass on Windows with CPython 3.14.7: 179 C-extension tests and 176 pure
Python tests.