# HG changeset patch # User Gregory Szorc # Date 2018-09-07 17:18:20 # Node ID 8f2c0d1b454c90800d7de5517fde3e2fad2631cd # Parent f296c0b366c81a673d570e6b2ff15c5493a8fd92 util: update lrucachedict order during get() get() should have the same semantics as __getitem__ for item retrieval. Differential Revision: https://phab.mercurial-scm.org/D4506 diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -1332,7 +1332,7 @@ class lrucachedict(object): def get(self, k, default=None): try: - return self._cache[k].value + return self.__getitem__(k) except KeyError: return default diff --git a/tests/test-lrucachedict.py b/tests/test-lrucachedict.py --- a/tests/test-lrucachedict.py +++ b/tests/test-lrucachedict.py @@ -67,6 +67,18 @@ class testlrucachedict(unittest.TestCase for key in ('a', 'b'): self.assertIn(key, d) + def testget(self): + d = util.lrucachedict(4) + d['a'] = 'va' + d['b'] = 'vb' + d['c'] = 'vc' + + self.assertIsNone(d.get('missing')) + self.assertEqual(list(d), ['c', 'b', 'a']) + + self.assertEqual(d.get('a'), 'va') + self.assertEqual(list(d), ['a', 'c', 'b']) + def testcopypartial(self): d = util.lrucachedict(4) d.insert('a', 'va', cost=4)