Bläddra i källkod

Convert to Python 3: `dict` key iterations

Alois Mahdal 2 år sedan
förälder
incheckning
55db18790d
2 ändrade filer med 6 tillägg och 8 borttagningar
  1. 5
    7
      sznqalibs/hoover.py
  2. 1
    1
      tests/test_hoover.py

+ 5
- 7
sznqalibs/hoover.py Visa fil

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

+ 1
- 1
tests/test_hoover.py Visa fil

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