Anonymous committed dc1a6cb

use .iter* version of dict methods when possible

Comments (0)

Files changed (7)

-# Copyright (c) 2003-2010 LOGILAB S.A. (Paris, FRANCE).
+# Copyright (c) 2003-2012 LOGILAB S.A. (Paris, FRANCE).
 # Copyright (c) 2009-2010 Arista Networks, Inc.
 # --
 # This program is free software; you can redistribute it and/or modify it under
     @check_messages('C0102', 'C0103')
     def visit_class(self, node):
         self._check_name('class',, node)
-        for attr, anodes in node.instance_attrs.items():
+        for attr, anodes in node.instance_attrs.iteritems():
             self._check_name('attr', attr, anodes[0])
     @check_messages('C0102', 'C0103')
         if 'W0201' not in self.active_msgs:
         defining_methods = self.config.defining_attr_methods
-        for attr, nodes in cnode.instance_attrs.items():
+        for attr, nodes in cnode.instance_attrs.iteritems():
             nodes = [n for n in nodes if not
                     isinstance(n.statement(), (astng.Delete, astng.AugAssign))]
             if not nodes:
     def _check_accessed_members(self, node, accessed):
         """check that accessed members are defined"""
         # XXX refactor, probably much simpler now that E0201 is in type checker
-        for attr, nodes in accessed.items():
+        for attr, nodes in accessed.iteritems():
             # deactivate "except doesn't do anything", that's expected
             # pylint: disable=W0704
             # is it a class attribute ?
-# Copyright (c) 2003-2010 LOGILAB S.A. (Paris, FRANCE).
+# Copyright (c) 2003-2012 LOGILAB S.A. (Paris, FRANCE).
 # --
 # This program is free software; you can redistribute it and/or modify it under
         assert mode == 'internal'
         filter_func = lambda x: is_standard_module(x, (package_dir,))
     result = {}
-    for importee, importers in dep_info.items():
+    for importee, importers in dep_info.iteritems():
         if filter_func(importee):
             result[importee] = importers
     return result
     done = {}
     printer = DotBackend(filename[:-4], rankdir = "LR")
     printer.emit('URL="." node[shape="box"]')
-    for modname, dependencies in dep_info.items():
+    for modname, dependencies in dep_info.iteritems():
         done[modname] = 1
         for modname in dependencies:
             if modname not in done:
                 done[modname] = 1
-    for depmodname, dependencies in dep_info.items():
+    for depmodname, dependencies in dep_info.iteritems():
         for modname in dependencies:
             printer.emit_edge(modname, depmodname)
     def report_external_dependencies(self, sect, _, dummy):
         """return a verbatim layout for displaying dependencies"""
-        dep_info = make_tree_defs(self._external_dependencies_info().items())
+        dep_info = make_tree_defs(self._external_dependencies_info().iteritems())
         if not dep_info:
             raise EmptyReport()
         tree_str = repr_tree_defs(dep_info)


         self._to_consume = [(copy(node.locals), {}, 'module')]
         self._vars = []
-        for name, stmts in node.locals.items():
+        for name, stmts in node.locals.iteritems():
             if is_builtin(name) and not is_inside_except(stmts[0]):
                 # do not print Redefining builtin for additional builtins
                 self.add_message('W0622', args=name, node=stmts[0])
         # don't check unused imports in __init__ files
         if not self.config.init_import and node.package:
-        for name, stmts in not_consumed.items():
+        for name, stmts in not_consumed.iteritems():
             stmt = stmts[0]
             if isinstance(stmt, astng.Import):
                 self.add_message('W0611', args=name, node=stmt)
     def disable_reporters(self):
         """disable all reporters"""
-        for reporters in self._reports.values():
+        for reporters in self._reports.itervalues():
             for report_id, _title, _cb in reporters:
     def get_checkers(self):
         """return all available checkers as a list"""
-        return [self] + [c for checkers in self._checkers.values()
+        return [self] + [c for checkers in self._checkers.itervalues()
                          for c in checkers if c is not self]
     def prepare_checkers(self):
         self.current_file = filepath or modname
         self.stats['by_module'][modname] = {}
         self.stats['by_module'][modname]['statement'] = 0
-        for msg_cat in MSG_TYPES.values():
+        for msg_cat in MSG_TYPES.itervalues():
             self.stats['by_module'][modname][msg_cat] = 0
         # XXX hack, to be correct we need to keep module_msgs_state
         # for every analyzed module (the problem stands with localized
         self.stats = { 'by_module' : {},
                        'by_msg' : {},
-        for msg_cat in MSG_TYPES.values():
+        for msg_cat in MSG_TYPES.itervalues():
             self.stats[msg_cat] = 0
     def close(self):
         # don't print this report when we didn't detected any errors
         raise EmptyReport()
     in_order = sorted([(value, msg_id)
-                       for msg_id, value in stats['by_msg'].items()
+                       for msg_id, value in stats['by_msg'].iteritems()
                        if not msg_id.startswith('I')])
     lines = ('message id', 'occurrences')
     by_mod = {}
     for m_type in ('fatal', 'error', 'warning', 'refactor', 'convention'):
         total = stats[m_type]
-        for module in stats['by_module'].keys():
+        for module in stats['by_module'].iterkeys():
             mod_total = stats['by_module'][module][m_type]
             if total == 0:
                 percent = 0
                 percent = float((mod_total)*100) / total
             by_mod.setdefault(module, {})[m_type] = percent
     sorted_result = []
-    for module, mod_info in by_mod.items():
+    for module, mod_info in by_mod.iteritems():


-# Copyright (c) 2004-2010 LOGILAB S.A. (Paris, FRANCE).
+# Copyright (c) 2004-2012 LOGILAB S.A. (Paris, FRANCE).
 # --
 # This program is free software; you can redistribute it and/or modify it under
         msgs_dict = checker.msgs
         chkid = None
-        for msgid, (msg, msgdescr) in msgs_dict.items():
+        for msgid, (msg, msgdescr) in msgs_dict.iteritems():
             # avoid duplicate / malformed ids
             assert msgid not in self._messages, \
                    'Message id %r is already defined' % msgid
             msgs = self._msgs_state
             msgs[msg.msgid] = False
             # sync configuration object
-            self.config.disable_msg = [mid for mid, val in msgs.items()
+            self.config.disable_msg = [mid for mid, val in msgs.iteritems()
                                        if not val]
     def enable(self, msgid, scope='package', line=None):
             msgs = self._msgs_state
             msgs[msg.msgid] = True
             # sync configuration object
-            self.config.enable = [mid for mid, val in msgs.items() if val]
+            self.config.enable = [mid for mid, val in msgs.iteritems() if val]
     def check_message_id(self, msgid):
         """raise UnknownMessage if the message id is not defined"""
                     by_checker[] = [list(checker.options_and_values()),
-        for checker, (options, msgs, reports) in by_checker.items():
+        for checker, (options, msgs, reports) in by_checker.iteritems():
             prefix = ''
             title = '%s checker' % checker
             print title
                 title = ('%smessages' % prefix).capitalize()
                 print title
                 print '~' * len(title)
-                for msgid in sort_msgs(msgs.keys()):
+                for msgid in sort_msgs(msgs.iterkeys()):
                     print self.get_message_help(msgid, False)
             if reports:
         """output full messages list documentation in ReST format"""
         msgids = []
         for checker in self.get_checkers():
-            for msgid in checker.msgs.keys():
+            for msgid in checker.msgs.iterkeys():
         for msgid in msgids:
         """add some stats entries to the statistic dictionary
         raise an AssertionError if there is a key conflict
-        for key, value in kwargs.items():
+        for key, value in kwargs.iteritems():
             if key[-1] == '_':
                 key = key[:-1]
             assert key not in self.stats