Skip to content

safe_dump of a dict with a tuple key produces YAML that safe_load cannot parse #938

Description

@BoxiYu
import yaml
s = yaml.safe_dump({(1, 2): 0})   # succeeds -> '? - 1\n  - 2\n: 0\n'
yaml.safe_load(s)                 # ConstructorError: while constructing a mapping ...

Environment: PyYAML 6.0.3, Python 3.13.12.

safe_dump produces YAML with a complex (sequence) key that safe_load refuses to construct — a round-trip asymmetry. Found by round-trip testing (233/3000 random structured inputs).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    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