comparison mercurial/config.py @ 16865:a6543fdcf869

config: make sortdict keys() and iterkeys() methods respect the item order The config.sortdict class is a simple "sorted dictionary" container class, based on python's regular dict container. The main difference compared to regular dicts is that sortdicts remember the order in which items have been added to it. Without this patch the items() method returns the sortdict elements in the right order. However, getting the list of keys by using the keys() or iterkeys() methods, and consequencly, looping through the container elements in a for loop does not respect that order. This patch fixes this problem.
author Angel Ezquerra <angel.ezquerra@gmail.com>
date Tue, 29 May 2012 23:26:55 +0200
parents f350021ee32e
children 5d3d77b3c512
comparison
equal deleted inserted replaced
16864:92cfde8728ac 16865:a6543fdcf869
33 def items(self): 33 def items(self):
34 return [(k, self[k]) for k in self._list] 34 return [(k, self[k]) for k in self._list]
35 def __delitem__(self, key): 35 def __delitem__(self, key):
36 dict.__delitem__(self, key) 36 dict.__delitem__(self, key)
37 self._list.remove(key) 37 self._list.remove(key)
38 def keys(self):
39 return self._list
40 def iterkeys(self):
41 return self._list.__iter__()
38 42
39 class config(object): 43 class config(object):
40 def __init__(self, data=None): 44 def __init__(self, data=None):
41 self._data = {} 45 self._data = {}
42 self._source = {} 46 self._source = {}