Skip to content

Commit 6d86209

Browse files
[FIX] Support MessagesStore.get_message_definitions interface.
Thanks #14 for more readable and better solution.
1 parent 9e9f084 commit 6d86209

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

pylint_plugin_utils/__init__.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,26 @@ def suppress_message(linter, checker_method, message_id_or_symbol, test_func):
117117
# compatability with <=1.2 and >=1.3
118118
msgs_store = getattr(linter, 'msgs_store', linter)
119119

120-
# pylint 2.0 renamed check_message_id to get_message_definition in:
121-
# https://github.com/PyCQA/pylint/commit/5ccbf9eaa54c0c302c9180bdfb745566c16e416d
122-
# pylint 2.3.0 renamed get_message_definition to get_message_definitions in:
123-
# https://github.com/PyCQA/pylint/commit/da67a9da682e51844fbc674229ff6619eb9c816a
124-
if hasattr(msgs_store, 'check_message_id'):
125-
get_message_definitions = msgs_store.check_message_id
126-
elif hasattr(msgs_store, 'get_message_definition'):
127-
get_message_definitions = msgs_store.get_message_definition
128-
else:
129-
get_message_definitions = msgs_store.get_message_definitions
120+
def get_message_definitions(message_id_or_symbol):
121+
if hasattr(msgs_store, 'check_message_id'):
122+
return [msgs_store.check_message_id(message_id_or_symbol)]
123+
# pylint 2.0 renamed check_message_id to get_message_definition in:
124+
# https://github.com/PyCQA/pylint/commit/5ccbf9eaa54c0c302c9180bdfb745566c16e416d
125+
elif hasattr(msgs_store, 'get_message_definition'):
126+
return [msgs_store.get_message_definition(message_id_or_symbol)]
127+
# pylint 2.3.0 renamed get_message_definition to get_message_definitions in:
128+
# https://github.com/PyCQA/pylint/commit/da67a9da682e51844fbc674229ff6619eb9c816a
129+
elif hasattr(msgs_store, 'get_message_definitions'):
130+
return msgs_store.get_message_definitions(message_id_or_symbol)
131+
else:
132+
raise ValueError('pylint.utils.MessagesStore does not have a get_message_definition(s) method')
130133

131134
try:
132-
pylint_message = get_message_definitions(message_id_or_symbol)
133-
pylint_message = pylint_message[0] if isinstance(pylint_message, (list, tuple)) else pylint_message
134-
symbols = [s for s in (pylint_message.msgid, pylint_message.symbol) if s is not None]
135+
pylint_messages = get_message_definitions(message_id_or_symbol)
136+
symbols = [symbol
137+
for pylint_message in pylint_messages
138+
for symbol in (pylint_message.msgid, pylint_message.symbol)
139+
if symbol is not None]
135140
except UnknownMessage:
136141
# This can happen due to mismatches of pylint versions and plugin expectations of available messages
137142
symbols = [message_id_or_symbol]

0 commit comments

Comments
 (0)