From b97f47c481288f6c399af41cc33e0ad349842e8b Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 29 Oct 2010 16:29:37 -0700 Subject: [PATCH] Fix LazyItemsDict.__deepcopy__() for python 2.7. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit In python-2.7, changes in deepcopy() make LazyItemsDict.__deepcopy__() fail in some cases. Thanks to Diego E. Pettenò for reporting. --- pym/portage/tests/ebuild/test_config.py | 22 ++++++++++++++++++++++ pym/portage/util/__init__.py | 15 ++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/pym/portage/tests/ebuild/test_config.py b/pym/portage/tests/ebuild/test_config.py index 5af8da5fb..764031707 100644 --- a/pym/portage/tests/ebuild/test_config.py +++ b/pym/portage/tests/ebuild/test_config.py @@ -10,6 +10,28 @@ from portage.tests.resolver.ResolverPlayground import ResolverPlayground, Resolv class ConfigTestCase(TestCase): + def testClone(self): + """ + Test the clone via constructor. + """ + + ebuilds = { + "dev-libs/A-1": { }, + } + + playground = ResolverPlayground(ebuilds=ebuilds) + try: + settings = config(clone=playground.settings) + result = playground.run(["=dev-libs/A-1"]) + pkg, existing_node = result.depgraph._select_package( + playground.root, "=dev-libs/A-1") + settings.setcpv(pkg) + + # clone after setcpv tests deepcopy of LazyItemsDict + settings2 = config(clone=settings) + finally: + playground.cleanup() + def testFeaturesMutation(self): """ Test whether mutation of config.features updates the FEATURES diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py index 0c2dc3382..a0f578eb4 100644 --- a/pym/portage/util/__init__.py +++ b/pym/portage/util/__init__.py @@ -1341,15 +1341,12 @@ class LazyItemsDict(UserDict): k_copy = deepcopy(k, memo) if k in self.lazy_items: lazy_item = self.lazy_items[k] - try: - result.lazy_items[k_copy] = deepcopy(lazy_item, memo) - except TypeError: - if not lazy_item.singleton: - raise - UserDict.__setitem__(result, - k_copy, deepcopy(self[k], memo)) - else: - UserDict.__setitem__(result, k_copy, None) + if not lazy_item.singleton: + raise TypeError("LazyItemsDict deepcopy is " + \ + "unsafe with lazy items that " + \ + "are not singletons: %s" % (lazy_item,)) + UserDict.__setitem__(result, + k_copy, deepcopy(self[k], memo)) else: UserDict.__setitem__(result, k_copy, deepcopy(self[k], memo)) return result -- 2.26.2