Modify

Ticket #23 (closed enhancement: fixed)

Opened 8 years ago

Last modified 8 years ago

Dictionary output not sorted.

Reported by: tim.hochberg@… Owned by: xi
Priority: normal Component: pyyaml
Severity: normal Keywords:
Cc:

Description

It is convenient to have YAML's output be consistent across runs. Some representers in PyYaml? do this already, but the dictionaries do not. I implemented a quick fix by replacing represent_dict with:

    def represent_dict(self, data):
        items = data.items()
        items.sort()
        return self.represent_mapping(u'tag:yaml.org,2002:map', items)

It might also be convenient to have custom sort orders as PyYaml? legacy does, but that's a bigger change.

Attachments

Change History

comment:1 Changed 8 years ago by xi

  • Status changed from new to closed
  • Resolution set to fixed

Fixed in [222].

Now represent_mapping converts a dictionary to a list of pairs and sorts it.

The easiest way to have custom sort is to define a custom representer and pass a suitably sorted list of pairs to represent_mapping.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.