Commits

Greg Noel  committed 37a5987

http://scons.tigris.org/issues/show_bug.cgi?id=2317

Apply the refactorings from the 'dict' fixer, less occurrences that were
manually audited to be safe. Also pick up changes in bin/sfsum, a Python
file that was not being scanned before.

  • Participants
  • Parent commits 338df4d

Comments (0)

Files changed (28)

File QMTest/scons_tdb.py

             dirs = [d for d in dircache.listdir(path)
                     if os.path.isdir(os.path.join(path, d))]
         else:
-            dirs = self.is_a_test.keys()
+            dirs = list(self.is_a_test.keys())
 
         dirs.sort()
         return dirs
                        for d in dircache.listdir(path)
                        if os.path.isdir(os.path.join(path, d))]
             else:
-                ids = self.is_a_test.keys()
+                ids = list(self.is_a_test.keys())
 
         if scan_subdirs:
             for d in dircache.listdir(path):

File bench/env.__setitem__.py

         'SOURCE'   : None,
         'SOURCES'  : None,
     }
-    _special_set_keys = _special_set.keys()
+    _special_set_keys = list(_special_set.keys())
     _valid_var = re.compile(r'[_a-zA-Z]\w*$')
     def __init__(self, **kw):
         self._dict = kw

File bin/SConsDoc.py

     def __init__(self):
         self._start_dispatch = {}
         self._end_dispatch = {}
-        keys = self.__class__.__dict__.keys()
+        keys = list(self.__class__.__dict__.keys())
         start_tag_method_names = [k for k in keys if k[:6] == 'start_']
         end_tag_method_names = [k for k in keys if k[:4] == 'end_']
         for method_name in start_tag_method_names:
 
     # Hard-coded search for 'Open' bugs.  This should be easily
     # generalized once we figure out other things for this script to do.
-    bugs = filter(lambda x: x.status == 'Open', Artifacts['Bugs'])
+    bugs = [x for x in Artifacts['Bugs'] if x.status == 'Open']
 
-    print Artifacts.keys()
+    print list(Artifacts.keys())
 
     print "%d open bugs" % len(bugs)
 

File src/engine/SCons/Action.py

         for act in self.list:
             for var in act.get_varlist(target, source, env, executor):
                 result[var] = True
-        return result.keys()
+        return list(result.keys())
 
 class ActionCaller:
     """A class for delaying calling an Action function with specific

File src/engine/SCons/ActionTests.py

     def get(self, key, value=None):
         return self.d.get(key, value)
     def items(self):
-        return self.d.items()
+        return list(self.d.items())
     def Dictionary(self):
         return self.d
     def Clone(self, **kw):

File src/engine/SCons/Builder.py

         self.source_ext_match = source_ext_match
 
     def src_suffixes(self):
-        return self.keys()
+        return list(self.keys())
 
     def add_action(self, suffix, action):
         """Add a suffix-action pair to the mapping.
             raise UserError("Ambiguous suffixes after environment substitution: %s == %s == %s" % (e.args[0], e.args[1], e.args[2]))
         if ret is None:
             raise UserError("While building `%s' from `%s': Don't know how to build from a source file with suffix `%s'.  Expected a suffix in this list: %s." % \
-                            (repr(list(map(str, target))), repr(list(map(str, source))), ext, repr(self.keys())))
+                            (repr(list(map(str, target))), repr(list(map(str, source))), ext, repr(list(self.keys()))))
         return ret
 
 class CallableSelector(SCons.Util.Selector):
         name (if there is one) or the name of the class (by default)."""
 
         try:
-            index = env['BUILDERS'].values().index(self)
-            return env['BUILDERS'].keys()[index]
+            index = list(env['BUILDERS'].values()).index(self)
+            return list(env['BUILDERS'].keys())[index]
         except (AttributeError, KeyError, TypeError, ValueError):
             try:
                 return self.name

File src/engine/SCons/BuilderTests.py

     def has_key(self, item):
         return item in self.d
     def keys(self):
-        return self.d.keys()
+        return list(self.d.keys())
     def get(self, key, value=None):
         return self.d.get(key, value)
     def Override(self, overrides):
     def _update(self, dict):
         self.d.update(dict)
     def items(self):
-        return self.d.items()
+        return list(self.d.items())
     def sig_dict(self):
         d = {}
         for k,v in self.items(): d[k] = v

File src/engine/SCons/Environment.py

         # Freeze the keys of self._special_set in a list for use by
         # methods that need to check.  (Empirically, list scanning has
         # gotten better than dict.has_key() in Python 2.5.)
-        self._special_set_keys = self._special_set.keys()
+        self._special_set_keys = list(self._special_set.keys())
 
     def __cmp__(self, other):
         return cmp(self._dict, other._dict)
         return self._dict.__contains__(key)
 
     def items(self):
-        return self._dict.items()
+        return list(self._dict.items())
 
     def arg2nodes(self, args, node_factory=_null, lookup_list=_null, **kw):
         if node_factory is _null:
             variables = kw['options']
             del kw['options']
         self.Replace(**kw)
-        keys = kw.keys()
+        keys = list(kw.keys())
         if variables:
-            keys = keys + variables.keys()
+            keys = keys + list(variables.keys())
             variables.Update(self)
 
         save = {}
         return d
     def items(self):
         """Emulates the items() method of dictionaries."""
-        return self.Dictionary().items()
+        return list(self.Dictionary().items())
 
     # Overridden private construction environment methods.
     def _update(self, dict):

File src/engine/SCons/EnvironmentTests.py

     s1 = "env1 = {\n"
     s2 = "env2 = {\n"
     d = {}
-    for k in env1._dict.keys() + env2._dict.keys():
+    for k in list(env1._dict.keys()) + list(env2._dict.keys()):
         d[k] = None
     for k in sorted(d.keys()):
         if k in env1:
     s1 = "d1 = {\n"
     s2 = "d2 = {\n"
     d = {}
-    for k in d1.keys() + d2.keys():
+    for k in list(d1.keys()) + list(d2.keys()):
         d[k] = None
     for k in sorted(d.keys()):
         if k in d1:
         """Test the SubstitutionEnvironment items() method
         """
         env = SubstitutionEnvironment(XXX = 'x', YYY = 'y')
-        items = env.items()
+        items = list(env.items())
         assert items == [('XXX','x'), ('YYY','y')], items
 
     def test_arg2nodes(self):

File src/engine/SCons/Node/FS.py

         in any way (or ignored, passing None is common).
         """
         entries = self.entries
-        names = entries.keys()
+        names = list(entries.keys())
         names.remove('.')
         names.remove('..')
         func(arg, self, names)

File src/engine/SCons/Scanner/Dir.py

         # mixed Node types (Dirs and Files, for example) has a Dir as
         # the first entry.
         return []
-    entry_list = sorted(filter(do_not_scan, entries.keys()))
+    entry_list = sorted(filter(do_not_scan, list(entries.keys())))
     return [entries[n] for n in entry_list]
 
 # Local Variables:

File src/engine/SCons/Scanner/LaTeX.py

                      'bibliographystyle': 'BSTINPUTS',
                      'usepackage': 'TEXINPUTS',
                      'lstinputlisting': 'TEXINPUTS'}
-    env_variables = SCons.Util.unique(keyword_paths.values())
+    env_variables = SCons.Util.unique(list(keyword_paths.values()))
 
     def __init__(self, name, suffixes, graphics_extensions, *args, **kw):
 

File src/engine/SCons/Scanner/ScannerTests.py

         dict = {}
         dict[s] = 777
         i = hash(id(s))
-        h = hash(dict.keys()[0])
+        h = hash(list(dict.keys())[0])
         self.failUnless(h == i,
                         "hash Scanner base class expected %s, got %s" % (i, h))
 

File src/engine/SCons/Scanner/__init__.py

 
         if skeys is _null:
             if SCons.Util.is_Dict(function):
-                skeys = function.keys()
+                skeys = list(function.keys())
             else:
                 skeys = []
         self.skeys = skeys
     def __init__(self, dict, *args, **kw):
         Base.__init__(self, None, *args, **kw)
         self.dict = dict
-        self.skeys = dict.keys()
+        self.skeys = list(dict.keys())
 
     def __call__(self, node, env, path = ()):
         return self.select(node)(node, env, path)

File src/engine/SCons/Script/SConsOptions.py

     debug_options = ["count", "explain", "findlibs",
                      "includes", "memoizer", "memory", "objects",
                      "pdb", "presub", "stacktrace",
-                     "time"] + deprecated_debug_options.keys()
+                     "time"] + list(deprecated_debug_options.keys())
 
     def opt_debug(option, opt, value, parser,
                   debug_options=debug_options,

File src/engine/SCons/Tool/intelc.py

     u = {}
     for x in s:
         u[x] = 1
-    return u.keys()
+    return list(u.keys())
 
 def linux_ver_normalize(vstr):
     """Normalize a Linux compiler version number.
         abi = valid_abis[abi]
     except KeyError:
         raise SCons.Errors.UserError("Intel compiler: Invalid ABI %s, valid values are %s"% \
-              (abi, valid_abis.keys()))
+              (abi, list(valid_abis.keys())))
     return abi
 
 def vercmp(a, b):

File src/engine/SCons/Tool/javac.py

                find_java_files(result, dirpath, filenames)
             entry.walk(find_java_files, result)
 
-            slist.extend(result.keys())
+            slist.extend(list(result.keys()))
         else:
             raise SCons.Errors.UserError("Java source must be File or Dir, not '%s'" % entry.__class__)
 

File src/engine/SCons/Tool/packaging/rpm.py

         def strip_country_code(tag):
             return tag[:-2]
 
-        replacements = self.tagset.items()
+        replacements = list(self.tagset.items())
 
         str = ""
         #domestic = [ (k,v) for k,v in replacements if not is_international(k) ]

File src/engine/SCons/Tool/textfile.py

     else:
         d = env['SUBST_DICT']
         if is_Dict(d):
-            d = d.items()
+            d = list(d.items())
         elif is_Sequence(d):
             pass
         else:

File src/engine/SCons/Util.py

         return dict
 
     def items(self):
-        return list(zip(self._keys, self.values()))
+        return list(zip(self._keys, list(self.values())))
 
     def keys(self):
         return self._keys[:]
     except TypeError:
         pass    # move on to the next method
     else:
-        return u.keys()
+        return list(u.keys())
     del u
 
     # We can't hash all the elements.  Second fastest is to sort,

File src/engine/SCons/Variables/VariablesTests.py

                  "42",
                  check,
                  lambda x: int(x) + 12)
-        keys = opts.keys()
+        keys = list(opts.keys())
         assert keys == ['VAR1', 'VAR2'], keys
 
     def test_Add(self):

File src/engine/SCons/compat/_scons_sets.py

     __str__ = __repr__
 
     def _repr(self, sort_them=False):
-        elements = self._data.keys()
+        elements = list(self._data.keys())
         if sort_them:
             elements.sort()
         return '%s(%r)' % (self.__class__.__name__, elements)

File src/engine/SCons/dblite.py

     self._needs_sync = 0001
 
   def keys(self):
-    return self._dict.keys()
+    return list(self._dict.keys())
 
   def has_key(self, key):
     return key in self._dict

File test/ARGUMENTS.py

 
 test.write('SConstruct', """
 foo = open('foo.out', 'wb')
-for k in sorted(list(ARGUMENTS.keys())):
+for k in sorted(ARGUMENTS.keys()):
     foo.write(k + " = " + ARGUMENTS[k] + "\\n")
 foo.close()
 """)

File test/LoadableModule.py

     'freebsd4' : no_dl_lib,
     'linux2' : use_dl_lib,
 }
-platforms_with_dlopen = dlopen_line.keys()
+platforms_with_dlopen = list(dlopen_line.keys())
 
 test.write('SConstruct', """
 env = Environment()

File test/SConscript/variables.py

 test.write("SConstruct", """
 x = 'x'
 y = 'zoom'
-Export(globals().keys())                         
+Export(list(globals().keys()))                         
 SConscript('SConscript')
 """)
 
 test.write("SConstruct", """
 x = 'x'
 y = 'zoom'
-SConscript('SConscript', globals().keys())
+SConscript('SConscript', list(globals().keys()))
 """)
 
 test.run(arguments = ".")

File test/scons-time/help/all-subcommands.py

 except: pass
 
 # Extract all subcommands from the the do_*() functions.
-functions = globals['SConsTimer'].__dict__.keys()
+functions = list(globals['SConsTimer'].__dict__.keys())
 do_funcs = [x for x in functions if x[:3] == 'do_']
 
 subcommands = [x[3:] for x in do_funcs]