diff options
author | Brett Cannon <brett@python.org> | 2014-08-29 11:16:29 -0400 |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2014-08-29 11:16:29 -0400 |
commit | 131810f8df6431ffef5d0cf345d67aeec7c3c605 (patch) | |
tree | d4c1219e564ccffc8feeb3b42785038a47cc14e6 /utils.py | |
parent | 2995e293950edc39b0466d1274affc1136c066c8 (diff) | |
download | pylint-131810f8df6431ffef5d0cf345d67aeec7c3c605.tar.gz |
Modernize to the point of working for Python 2.7 still
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 30 |
1 files changed, 16 insertions, 14 deletions
@@ -37,6 +37,8 @@ from astroid.modutils import modpath_from_file, get_module_files, \ file_from_modpath, load_module_from_file from pylint.interfaces import IRawChecker, ITokenChecker, UNDEFINED +import six +from six.moves import zip class UnknownMessage(Exception): @@ -54,7 +56,7 @@ MSG_TYPES = { 'E' : 'error', 'F' : 'fatal' } -MSG_TYPES_LONG = {v: k for k, v in MSG_TYPES.iteritems()} +MSG_TYPES_LONG = {v: k for k, v in six.iteritems(MSG_TYPES)} MSG_TYPES_STATUS = { 'I' : 0, @@ -265,7 +267,7 @@ class MessagesHandlerMixIn(object): msgs = self._msgs_state msgs[msg.msgid] = False # sync configuration object - self.config.disable_msg = [mid for mid, val in msgs.iteritems() + self.config.disable_msg = [mid for mid, val in six.iteritems(msgs) if not val] def enable(self, msgid, scope='package', line=None, ignore_unknown=False): @@ -303,7 +305,7 @@ class MessagesHandlerMixIn(object): msgs = self._msgs_state msgs[msg.msgid] = True # sync configuration object - self.config.enable = [mid for mid, val in msgs.iteritems() if val] + self.config.enable = [mid for mid, val in six.iteritems(msgs) if val] def get_message_state_scope(self, msgid, line=None, confidence=UNDEFINED): """Returns the scope at which a message was enabled/disabled.""" @@ -425,7 +427,7 @@ class MessagesHandlerMixIn(object): by_checker[checker.name] = [list(checker.options_and_values()), dict(checker.msgs), list(checker.reports)] - for checker, (options, msgs, reports) in by_checker.iteritems(): + for checker, (options, msgs, reports) in six.iteritems(by_checker): prefix = '' title = '%s checker' % checker print(title) @@ -441,7 +443,7 @@ class MessagesHandlerMixIn(object): title = ('%smessages' % prefix).capitalize() print(title) print('~' * len(title)) - for msgid, msg in sorted(msgs.iteritems(), + for msgid, msg in sorted(six.iteritems(msgs), key=lambda kv: (_MSG_ORDER.index(kv[0][0]), kv[1])): msg = build_message_def(checker, msgid, msg) print(msg.format_help(checkerref=False)) @@ -468,7 +470,7 @@ class FileState(object): def collect_block_lines(self, msgs_store, module_node): """Walk the AST to collect block level options line numbers.""" - for msg, lines in self._module_msgs_state.iteritems(): + for msg, lines in six.iteritems(self._module_msgs_state): self._raw_module_msgs_state[msg] = lines.copy() orig_state = self._module_msgs_state.copy() self._module_msgs_state = {} @@ -502,7 +504,7 @@ class FileState(object): firstchildlineno = node.body[0].fromlineno else: firstchildlineno = last - for msgid, lines in msg_state.iteritems(): + for msgid, lines in six.iteritems(msg_state): for lineno, state in lines.items(): original_lineno = lineno if first <= lineno <= last: @@ -515,7 +517,7 @@ class FileState(object): else: first_ = lineno last_ = last - for line in xrange(first_, last_+1): + for line in range(first_, last_+1): # do not override existing entries if not line in self._module_msgs_state.get(msgid, ()): if line in lines: # state change in the same block @@ -552,8 +554,8 @@ class FileState(object): pass def iter_spurious_suppression_messages(self, msgs_store): - for warning, lines in self._raw_module_msgs_state.iteritems(): - for line, enable in lines.iteritems(): + for warning, lines in six.iteritems(self._raw_module_msgs_state): + for line, enable in six.iteritems(lines): if not enable and (warning, line) not in self._ignored_msgs: yield 'useless-suppression', line, \ (msgs_store.get_msg_display_string(warning),) @@ -584,7 +586,7 @@ class MessagesStore(object): @property def messages(self): """The list of all active messages.""" - return self._messages.itervalues() + return six.itervalues(self._messages) def add_renamed_message(self, old_id, old_symbol, new_symbol): """Register the old ID and symbol for a warning that was renamed. @@ -606,7 +608,7 @@ class MessagesStore(object): are the checker id and the two last the message id in this checker """ chkid = None - for msgid, msg_tuple in checker.msgs.iteritems(): + for msgid, msg_tuple in six.iteritems(checker.msgs): msg = build_message_def(checker, msgid, msg_tuple) assert msg.symbol not in self._messages, \ 'Message symbol %r is already defined' % msg.symbol @@ -659,7 +661,7 @@ class MessagesStore(object): def list_messages(self): """output full messages list documentation in ReST format""" - msgs = sorted(self._messages.itervalues(), key=lambda msg: msg.msgid) + msgs = sorted(six.itervalues(self._messages), key=lambda msg: msg.msgid) for msg in msgs: if not msg.may_be_emitted(): continue @@ -729,7 +731,7 @@ class ReportsHandlerMixIn(object): """add some stats entries to the statistic dictionary raise an AssertionError if there is a key conflict """ - for key, value in kwargs.iteritems(): + for key, value in six.iteritems(kwargs): if key[-1] == '_': key = key[:-1] assert key not in self.stats |