Ticket #74: yaml.patch

File yaml.patch, 746 bytes (added by idadesub@…, 6 years ago)

Extending the last patch to allow sorting of maps that may have different key types.

  • lib/yaml/representer.py

    diff --git lib/yaml/representer.py lib/yaml/representer.py
    index 5c9a76f..c704265 100644
    class BaseRepresenter: 
    123123            if not (isinstance(node_value, ScalarNode) and not node_value.style): 
    124124                best_style = False 
    125125            value.append((node_key, node_value)) 
    126         value.sort() 
     126        try: 
     127            value.sort() 
     128        except TypeError: 
     129            def sortkey(item): 
     130                key, value = item 
     131                return str(type(key)), key, value 
     132            value.sort(key=sortkey) 
    127133        if flow_style is None: 
    128134            if self.default_flow_style is not None: 
    129135                node.flow_style = self.default_flow_style