Patchwork [1,of,3] util: properly implement lrucachedict.get()

login
register
mail settings
Submitter Gregory Szorc
Date Aug. 23, 2016, 4:50 a.m.
Message ID <93a0220d9982345a030f.1471927819@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/16389/
State Accepted
Headers show

Comments

Gregory Szorc - Aug. 23, 2016, 4:50 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1471923037 25200
#      Mon Aug 22 20:30:37 2016 -0700
# Node ID 93a0220d9982345a030fe9a5b954beaeded51aad
# Parent  3f9e76e1d75968d5b4e23cf15fcdbe62cb45ad80
util: properly implement lrucachedict.get()

Before, it was returning the raw _lrucachenode instance instead of its
value.

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -646,17 +646,17 @@  class lrucachedict(object):
         # this node the oldest item.
         self._movetohead(node)
         self._head = node.next
 
     # Additional dict methods.
 
     def get(self, k, default=None):
         try:
-            return self._cache[k]
+            return self._cache[k].value
         except KeyError:
             return default
 
     def clear(self):
         n = self._head
         while n.key is not _notset:
             n.markempty()
             n = n.next
diff --git a/tests/test-lrucachedict.py b/tests/test-lrucachedict.py
--- a/tests/test-lrucachedict.py
+++ b/tests/test-lrucachedict.py
@@ -20,16 +20,19 @@  def test_lrucachedict():
 
     # all of these should be present
     printifpresent(d, ['a', 'b', 'c', 'd'])
 
     # 'a' should be dropped because it was least recently used
     d['e'] = 've'
     printifpresent(d, ['a', 'b', 'c', 'd', 'e'])
 
+    assert d.get('a') is None
+    assert d.get('e') == 've'
+
     # touch entries in some order (get or set).
     d['e']
     d['c'] = 'vc2'
     d['d']
     d['b'] = 'vb2'
 
     # 'e' should be dropped now
     d['f'] = 'vf'