Skip to content

packb accepts a dict with a tuple key but the result cannot be unpackb'd (round-trip asymmetry) #703

@BoxiYu

Description

@BoxiYu

packb serializes a mapping with a tuple key without error, but the produced bytes cannot be deserialized: unpackb decodes the tuple key as a list, then fails to use it as a dict key.

import msgpack
b = msgpack.packb({(1, 2): 0})            # succeeds (5 bytes)
msgpack.unpackb(b, strict_map_key=False)  # TypeError: unhashable type: 'list'

Environment: msgpack-python 1.2.1, Python 3.13.12.

Expected: either packb should raise on a key that cannot survive a round trip, or the limitation should be documented. Currently it is silent at pack time and only fails on unpack. Found by round-trip testing (106/3000 random structured inputs, all reducing to a tuple-keyed dict).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions