Ticket #3508: doc_MergeDict_py23.diff

File doc_MergeDict_py23.diff, 1008 bytes (added by thebanana, 9 years ago)

MergeDict patch that works with Python 2.3

  • datastructures.py

    === datastructures.py
    ==================================================================
     
    4343                return True
    4444        return False
    4545
     46    def __str__(self):
     47        '''
     48        Returns something like
     49
     50            "{'key1': 'val1', 'key2': 'val2', 'key3': 'val3'}"
     51
     52        instead of the generic "<object meta-data>" inherited from object.
     53        '''
     54        return str(dict(self.items()))
     55
     56    def __repr__(self):
     57        '''
     58        Returns something like
     59
     60            MergeDict({'key1': 'val1', 'key2': 'val2'}, {'key3': 'val3'})
     61
     62        instead of generic "<object meta-data>" inherited from object.
     63        '''
     64        dictreprs = ', '.join([repr(d) for d in self.dicts])
     65        return '%s(%s)' % (self.__class__.__name__, dictreprs)
     66
    4667class SortedDict(dict):
    4768    "A dictionary that keeps its keys in the order in which they're inserted."
    4869    def __init__(self, data=None):
Back to Top