Ticket #161 (new enhancement)

Opened 4 years ago

Last modified 44 years ago

Recipie for using collections.OrderedDict as the primary pyyaml mapping type

Reported by: rdmurray@… Owned by: xi
Priority: normal Component: pyyaml
Severity: normal Keywords:


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.

Attachments Download (2.2 KB) - added by anonymous 4 years ago.

Change History

Changed 4 years ago by anonymous


Add a comment

Modify Ticket

Change Properties
<Author field>
as new
as The resolution will be set. Next status will be 'closed'
to The owner will be changed from xi. Next status will be 'new'
The owner will be changed from xi to anonymous. Next status will be 'assigned'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.