[PATCH] config: make sortdict keys() and iterkeys() methods respect the item order

Angel Ezquerra angel.ezquerra at gmail.com
Tue May 29 17:09:53 CDT 2012


# HG changeset patch
# User Angel Ezquerra <angel.ezquerra at gmail.com>
# Date 1338326815 -7200
# Node ID 265df2ebf0631cd01bd6c3aa0ebb94cbd640c438
# Parent  cb06046e10797e569bed05850318068f4a5d535c
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.

The test suite runs with no failures:

# Ran 401 tests, 37 skipped, 0 failed.

A few quick tests using --time show no change in performance.

diff --git a/mercurial/config.py b/mercurial/config.py
--- a/mercurial/config.py
+++ b/mercurial/config.py
@@ -35,6 +35,10 @@
     def __delitem__(self, key):
         dict.__delitem__(self, key)
         self._list.remove(key)
+    def keys(self):
+        return self._list
+    def iterkeys(self):
+        return self._list.__iter__()
 
 class config(object):
     def __init__(self, data=None):


More information about the Mercurial-devel mailing list