[py3k] explicitly build a list around dict methods

When we modify the return value from one of the dict methods, explicitly build a list from it to make things work on python3.

authorJulien Cristau <julien.cristau@logilab.fr>
changesetb2a05088292d
branchdefault
phasedraft
hiddenyes
parent revision#0eb748dcad73 [py3k] use dict.items() / dict.values() instead of .iter*
child revision#3768bbf88a84 [visitor] Implement iterator.__next__()
files modified by this revision
configuration.py
modutils.py
pytest.py
test/unittest_modutils.py
test/unittest_registry.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1406465279 -7200
# Sun Jul 27 14:47:59 2014 +0200
# Node ID b2a05088292d2c7b212e674915711e46805cebea
# Parent 0eb748dcad737e48c27ebfe77ffc11d59aafd042
[py3k] explicitly build a list around dict methods

When we modify the return value from one of the dict methods, explicitly
build a list from it to make things work on python3.

diff --git a/configuration.py b/configuration.py
@@ -531,11 +531,11 @@
1          if 'short' in optdict:
2              self._short_options[optdict['short']] = opt
3              args.append('-' + optdict['short'])
4              del optdict['short']
5          # cleanup option definition dict before giving it to optik
6 -        for key in optdict.keys():
7 +        for key in list(optdict.keys()):
8              if not key in self._optik_option_attrs:
9                  optdict.pop(key)
10          return args, optdict
11 
12      def cb_set_provider_option(self, option, opt, value, parser):
diff --git a/modutils.py b/modutils.py
@@ -455,11 +455,11 @@
13 
14 
15  def cleanup_sys_modules(directories):
16      """remove submodules of `directories` from `sys.modules`"""
17      cleaned = []
18 -    for modname, module in sys.modules.items():
19 +    for modname, module in list(sys.modules.items()):
20          modfile = getattr(module, '__file__', None)
21          if modfile:
22              for directory in directories:
23                  if modfile.startswith(directory):
24                      cleaned.append(modname)
diff --git a/pytest.py b/pytest.py
@@ -307,11 +307,11 @@
25        B/test/test_utils.py
26 
27      we **have** to clean sys.modules to make sure the correct test_utils
28      module is ran in B
29      """
30 -    for modname, mod in sys.modules.items():
31 +    for modname, mod in list(sys.modules.items()):
32          if mod is None:
33              continue
34          if not hasattr(mod, '__file__'):
35              # this is the case of some built-in modules like sys, imp, marshal
36              continue
diff --git a/test/unittest_modutils.py b/test/unittest_modutils.py
@@ -52,11 +52,11 @@
37  class ModuleFileTC(ModutilsTestCase):
38      package = "mypypa"
39 
40      def setUp(self):
41          super(ModuleFileTC, self).setUp()
42 -        for k in sys.path_importer_cache.keys():
43 +        for k in list(sys.path_importer_cache.keys()):
44              if 'MyPyPa' in k:
45                  del sys.path_importer_cache[k]
46 
47      def test_find_zipped_module(self):
48          mtype, mfile = modutils._module_file([self.package], [path.join(DATADIR, 'MyPyPa-0.1.0.zip')])
diff --git a/test/unittest_registry.py b/test/unittest_registry.py
@@ -177,11 +177,11 @@
49          store = RegistryStore()
50          store.setdefault('zereg')
51          with prepended_syspath(self.datadir):
52              store.register_objects([self.datapath('regobjects.py'),
53                                      self.datapath('regobjects2.py')])
54 -        self.assertEqual(['zereg'], store.keys())
55 +        self.assertEqual(['zereg'], list(store.keys()))
56          self.assertEqual(set(('appobject1', 'appobject2', 'appobject3')),
57                           set(store['zereg']))
58 
59 
60  class RegistrableInstanceTC(TestCase):