Patchwork util: drop unneeded override, sortdict.copy()

login
register
mail settings
Submitter Yuya Nishihara
Date May 17, 2017, 2:41 p.m.
Message ID <8f73e24a59c1d38132f1.1495032105@mimosa>
Download mbox | patch
Permalink /patch/20653/
State Accepted
Headers show

Comments

Yuya Nishihara - May 17, 2017, 2:41 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1495029716 -32400
#      Wed May 17 23:01:56 2017 +0900
# Node ID 8f73e24a59c1d38132f197f1dab296942865c2fc
# Parent  37bcb4665529f5cc59b8dffb1014ac0cab37492c
util: drop unneeded override, sortdict.copy()

OrderedDict.copy() returns self.__class__(self).
Augie Fackler - May 17, 2017, 7:40 p.m.
On Wed, May 17, 2017 at 11:41:45PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1495029716 -32400
> #      Wed May 17 23:01:56 2017 +0900
> # Node ID 8f73e24a59c1d38132f197f1dab296942865c2fc
> # Parent  37bcb4665529f5cc59b8dffb1014ac0cab37492c
> util: drop unneeded override, sortdict.copy()

queued, thanks

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -568,13 +568,21 @@  def cachefunc(func):
     return f
 
 class sortdict(collections.OrderedDict):
-    '''a simple sorted dictionary'''
+    '''a simple sorted dictionary
+
+    >>> d1 = sortdict([('a', 0), ('b', 1)])
+    >>> d2 = d1.copy()
+    >>> d2
+    sortdict([('a', 0), ('b', 1)])
+    >>> d2.update([('a', 2)])
+    >>> d2.keys() # should still be in last-set order
+    ['b', 'a']
+    '''
+
     def __setitem__(self, key, value):
         if key in self:
             del self[key]
         super(sortdict, self).__setitem__(key, value)
-    def copy(self):
-        return sortdict(self)
 
 class _lrucachenode(object):
     """A node in a doubly linked list.