Browse Source

Convert to Python 3: `dict` key iterations

Alois Mahdal 2 years ago
parent
commit
55db18790d
2 changed files with 6 additions and 8 deletions
  1. 5
    7
      sznqalibs/hoover.py
  2. 1
    1
      tests/test_hoover.py

+ 5
- 7
sznqalibs/hoover.py View File

654
 
654
 
655
     def __cleanup_data(self):
655
     def __cleanup_data(self):
656
         """remove hidden data; e.g. what was only there for _check_data"""
656
         """remove hidden data; e.g. what was only there for _check_data"""
657
-        for key in self.data.keys():
657
+        for key in self.data:
658
             if key.startswith("_"):
658
             if key.startswith("_"):
659
                 del self.data[key]
659
                 del self.data[key]
660
 
660
 
690
         are loaded ("DriverClass.settingName", the first discriminating part
690
         are loaded ("DriverClass.settingName", the first discriminating part
691
         is removed)"""
691
         is removed)"""
692
         if only_own:
692
         if only_own:
693
-            for ckey in settings.keys():
693
+            for ckey in settings:
694
                 driver_class_name, setting_name = ckey.split(".", 2)
694
                 driver_class_name, setting_name = ckey.split(".", 2)
695
                 if self.__class__.__name__ == driver_class_name:
695
                 if self.__class__.__name__ == driver_class_name:
696
                     self._settings[setting_name] = settings[ckey]
696
                     self._settings[setting_name] = settings[ckey]
794
         )
794
         )
795
 
795
 
796
     def _computed_stats(self):
796
     def _computed_stats(self):
797
-        computed = dict.fromkeys(self.formulas.keys())
797
+        computed = dict.fromkeys(self.formulas)
798
         for fname, fml in self.formulas.items():
798
         for fname, fml in self.formulas.items():
799
             try:
799
             try:
800
                 v = fml(self.generic_stats, self.driver_stats)
800
                 v = fml(self.generic_stats, self.driver_stats)
1007
             cn = {}
1007
             cn = {}
1008
             for affected in self._db.values():
1008
             for affected in self._db.values():
1009
                 for argset in affected:
1009
                 for argset in affected:
1010
-                    cn.update(dict.fromkeys(argset.keys()))
1010
+                    cn.update(dict.fromkeys(argset))
1011
                 return sorted(cn.keys())
1011
                 return sorted(cn.keys())
1012
 
1012
 
1013
         all_colnames = get_all_colnames()
1013
         all_colnames = get_all_colnames()
1380
         names = []
1380
         names = []
1381
         iterables = []
1381
         iterables = []
1382
 
1382
 
1383
-        keys = self.scheme.keys()
1384
-
1385
-        for key in keys:
1383
+        for key in self.scheme:
1386
             try:
1384
             try:
1387
                 iterables.append(self._get_iterable_for(key))
1385
                 iterables.append(self._get_iterable_for(key))
1388
             except KeyError:
1386
             except KeyError:

+ 1
- 1
tests/test_hoover.py View File

543
                 'b': hoover.Cartman.Iterable,
543
                 'b': hoover.Cartman.Iterable,
544
                 'c': a_mark
544
                 'c': a_mark
545
             }
545
             }
546
-            source = dict.fromkeys(scheme.keys(), [])
546
+            source = dict.fromkeys(scheme, [])
547
             iter(hoover.Cartman(source, scheme)).next()
547
             iter(hoover.Cartman(source, scheme)).next()
548
 
548
 
549
         self.assertRaises(ValueError, fn)
549
         self.assertRaises(ValueError, fn)