diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2018-09-18 09:38:59 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-09-18 09:48:55 +0200 |
commit | 1b756685aed259aa2cf67d33165dc656ee38fa59 (patch) | |
tree | 073040702ead5e8d718b3504b96a8c526f3493ff | |
parent | 1326aa56c13c1a3905238ad0d4b0c963ebcee4f4 (diff) | |
download | pylint-git-1b756685aed259aa2cf67d33165dc656ee38fa59.tar.gz |
Correct fallback when the lines out of the parse trees are in raw_module_msgs_state
`_raw_module_msgs_state` holds a mapping of messages to lines and their status, enabled
or disabled. As such, the correct solution is to check if any of those lines matches
the current line that's out of the AST, as well as to check if it's disabled or enabled,
since it can vary depending on the pragma that was used.
-rw-r--r-- | pylint/utils.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/pylint/utils.py b/pylint/utils.py index 7c7879cae..fb7075c9c 100644 --- a/pylint/utils.py +++ b/pylint/utils.py @@ -437,7 +437,22 @@ class MessagesHandlerMixIn: # This happens for example with a commented line at the end of a module. max_line_number = self.file_state.get_effective_max_line_number() if max_line_number and line > max_line_number: - fallback = msgid not in self.file_state._raw_module_msgs_state + fallback = True + lines = self.file_state._raw_module_msgs_state.get(msgid, {}) + + # Doesn't consider scopes, as a disable can be in a different scope + # than that of the current line. + closest_lines = reversed( + [ + (message_line, enable) + for message_line, enable in lines.items() + if message_line <= line + ] + ) + last_line, is_enabled = next(closest_lines, (None, None)) + if last_line is not None: + fallback = is_enabled + return self._msgs_state.get(msgid, fallback) return self._msgs_state.get(msgid, True) |