Ticket #101: pyyaml-slots.diff

File pyyaml-slots.diff, 1.2 KB (added by Joe Wreschnig, 5 years ago)

Patch to support lack of dict

  • lib/yaml/representer.py

     
    244244    def represent_yaml_object(self, tag, data, cls, flow_style=None): 
    245245        if hasattr(data, '__getstate__'): 
    246246            state = data.__getstate__() 
     247        elif getattr(data, '__slots__', None) and not hasattr(data, '__dict__'): 
     248            state = dict([(a, getattr(data, a)) for a in data.__slots__]) 
    247249        else: 
    248250            state = data.__dict__.copy() 
    249251        return self.represent_mapping(tag, state, flow_style=flow_style) 
  • lib/yaml/constructor.py

     
    412412            data.__setstate__(state) 
    413413        else: 
    414414            state = self.construct_mapping(node) 
    415             data.__dict__.update(state) 
     415            try: data.__dict__.update(state) 
     416            except AttributeError: 
     417                for key, value in state.iteritems(): 
     418                    setattr(data, key, value) 
    416419 
    417420    def construct_undefined(self, node): 
    418421        raise ConstructorError(None, None,