summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-03-11 06:17:35 +0000
committerZac Medico <zmedico@gentoo.org>2009-03-11 06:17:35 +0000
commit52ab3e9a9c8805c5a47ddbf22f3baaeb917a65f1 (patch)
tree253d69bccd3dbadae37e906993c580f5fdb7229c /pym
parent4c3b7049201096fccdd5cfd922e52fcb7701dea0 (diff)
downloadportage-52ab3e9a9c8805c5a47ddbf22f3baaeb917a65f1.tar.gz
portage-52ab3e9a9c8805c5a47ddbf22f3baaeb917a65f1.tar.bz2
portage-52ab3e9a9c8805c5a47ddbf22f3baaeb917a65f1.zip
If deepcopy() raises a TypeError for a lazy item that has been added via a
call to LazyItemsDict.addLazySingleton(), automatically evaluate the the singleton and instead call deepcopy() on the result. (trunk r12704) svn path=/main/branches/2.1.6/; revision=12959
Diffstat (limited to 'pym')
-rw-r--r--pym/portage/util.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/pym/portage/util.py b/pym/portage/util.py
index 2cb14b34d..92f658c58 100644
--- a/pym/portage/util.py
+++ b/pym/portage/util.py
@@ -1139,6 +1139,10 @@ class LazyItemsDict(dict):
If deepcopy() needs to work, this problem can be avoided by
implementing lazy items with normal (non-bound) functions.
+
+ If deepcopy() raises a TypeError for a lazy item that has been added
+ via a call to addLazySingleton(), the singleton will be automatically
+ evaluated and deepcopy() will instead be called on the result.
"""
if memo is None:
memo = {}
@@ -1148,9 +1152,17 @@ class LazyItemsDict(dict):
for k in self:
k_copy = deepcopy(k, memo)
if k in self.lazy_items:
- dict.__setitem__(result, k_copy, None)
- result.lazy_items[k_copy] = \
- deepcopy(self.lazy_items[k], memo)
+ lazy_item = self.lazy_items[k]
+ try:
+ result.lazy_items[k_copy] = deepcopy(lazy_item, memo)
+ except TypeError:
+ # If deepcopy fails for a lazy singleton, try to
+ # evaluate the singleton and deepcopy the result.
+ if not isinstance(lazy_item[0], self._SingletonWrapper):
+ raise
+ dict.__setitem__(result, k_copy, deepcopy(self[k], memo))
+ else:
+ dict.__setitem__(result, k_copy, None)
else:
dict.__setitem__(result, k_copy, deepcopy(self[k], memo))
return result