OrderedDict doesn't round-trip

Issue #61 resolved
Serhiy Storchaka
created an issue

Pickling OrderedDict was changed in Python 3.4. This caused a regression in PyYAML.

>>> from collections import OrderedDict
>>> import yaml
>>> od = OrderedDict((str(i), i) for i in range(5))
>>> od
OrderedDict([('0', 0), ('1', 1), ('2', 2), ('3', 3), ('4', 4)])
>>> yaml.load(yaml.dump(od))
OrderedDict([('1', 1), ('0', 0), ('3', 3), ('2', 2), ('4', 4)])
>>> yaml.dump(od)
"!!python/object/apply:collections.OrderedDict\ndictitems: {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4}\n"

For comparison in Python 2.7:

>>> yaml.load(yaml.dump(od))
OrderedDict([('0', 0), ('1', 1), ('2', 2), ('3', 3), ('4', 4)])
>>> yaml.dump(od)
"!!python/object/apply:collections.OrderedDict\n- - ['0', 0]\n  - ['1', 1]\n  - ['2', 2]\n  - ['3', 3]\n  - ['4', 4]\n"

Comments (1)

  1. Log in to comment