summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-03-07 00:05:30 +0000
committerZac Medico <zmedico@gentoo.org>2009-03-07 00:05:30 +0000
commitc2516a27486c22610c0602d4f7f6bfc30485ebcd (patch)
treee6a9fabea8db9243b6efccfc16a45cd15e0628fd
parent0064e2bfa8c4f43441fead6aae077f9c7162794d (diff)
downloadportage-c2516a27486c22610c0602d4f7f6bfc30485ebcd.tar.gz
portage-c2516a27486c22610c0602d4f7f6bfc30485ebcd.tar.bz2
portage-c2516a27486c22610c0602d4f7f6bfc30485ebcd.zip
Fix LazyItemsDict.update() to create new _SingletonWrapper instances that
reference self. svn path=/main/trunk/; revision=12772
-rw-r--r--pym/portage/util.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/pym/portage/util.py b/pym/portage/util.py
index bc181ba37..98a01c791 100644
--- a/pym/portage/util.py
+++ b/pym/portage/util.py
@@ -1082,8 +1082,8 @@ class LazyItemsDict(dict):
"""This is like addLazyItem except value_callable will only be called
a maximum of 1 time and the result will be cached for future requests."""
self.addLazyItem(item_key,
- self._SingletonWrapper(self, item_key, value_callable,
- *pargs, **kwargs))
+ self._SingletonWrapper(self, item_key, value_callable),
+ *pargs, **kwargs)
def update(self, *args, **kwargs):
if len(args) > 1:
@@ -1102,7 +1102,12 @@ class LazyItemsDict(dict):
dict.__setitem__(self, k, None)
else:
dict.__setitem__(self, k, map_obj[k])
- self.lazy_items.update(map_obj.lazy_items)
+ for k, v in map_obj.lazy_items.iteritems():
+ if isinstance(v[0], self._SingletonWrapper):
+ # Create a new wrapper that references self.
+ v = (self._SingletonWrapper(self, k, v[0]._callable),
+ v[1], v[2])
+ self.lazy_items[k] = v
else:
dict.update(self, map_obj)
if kwargs:
@@ -1182,17 +1187,15 @@ class LazyItemsDict(dict):
class _SingletonWrapper(object):
- __slots__ = ('_parent', '_key', '_callable', '_pargs', '_kwargs')
+ __slots__ = ('_parent', '_key', '_callable')
- def __init__(self, parent, key, value_callable, *pargs, **kwargs):
+ def __init__(self, parent, key, value_callable):
self._parent = parent
self._key = key
self._callable = value_callable
- self._pargs = pargs
- self._kwargs = kwargs
- def __call__(self):
- value = self._callable(*self._pargs, **self._kwargs)
+ def __call__(self, *pargs, **kwargs):
+ value = self._callable(*pargs, **kwargs)
self._parent[self._key] = value
return value