Ticket #23 (closed enhancement: fixed)

Opened 2 years ago

Last modified 2 years ago

Dictionary output not sorted.

Reported by: tim.hochberg@ieee.org Assigned to: 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

08/03/06 12:16:53 changed 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.


Add/Change #23 (Dictionary output not sorted.)




Change Properties
Action