From 5008ca93941f761c48b921d5379a6b2368cce5b4 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 11 Mar 2009 06:46:05 +0000 Subject: [PATCH] Fix LazyItemsDict.update() to create new _SingletonWrapper instances that reference self. (trunk r12772) svn path=/main/branches/2.1.6/; revision=13016 --- pym/portage/util.py | 21 ++++++++++++--------- 1 file 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 -- 2.26.2