Ticket #161 (new enhancement)
Recipie for using collections.OrderedDict as the primary pyyaml mapping type
| Reported by: | rdmurray@… | Owned by: | xi |
|---|---|---|---|
| Priority: | normal | Component: | pyyaml |
| Severity: | normal | Keywords: | |
| Cc: |
Description
I know ticket #29 was closed as won't fix, but the Python3 OrderedDict? is a standard library type, and for the project I'm working on (my first use of yaml) I wouldn't be able to use yaml unless mapping key order is maintained across load/dump.
To save other people the trouble of figuring out how to do this, the attached recipe seems to work to make pyyaml use collections.OrderedDict? as the primary object type for mappings, instead of the regular dict.
It involves one bit of monkey patching and includes modified versions of a couple methods from version 3.09 of pyyaml. It modifies Constructor and Representer, but could easily be changed to use SafeConstrutor? and SafeRepresenter? if that's what the application needs.
I think it would lovely if collections.OrderedDict? was used normally, or at least optionally.

