From 9e9f084abde67a4352a02f0f17c7c6416a3bad8d Mon Sep 17 00:00:00 2001 From: Shepilov Vladislav Date: Wed, 27 Feb 2019 15:27:27 +0300 Subject: [PATCH 1/2] [FIX] add support for pylint 2.3.0 (https://github.com/PyCQA/pylint/commit/da67a9da682e51844fbc674229ff6619eb9c816a) --- pylint_plugin_utils/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pylint_plugin_utils/__init__.py b/pylint_plugin_utils/__init__.py index 8e97f8e..c095ebb 100644 --- a/pylint_plugin_utils/__init__.py +++ b/pylint_plugin_utils/__init__.py @@ -119,13 +119,18 @@ def suppress_message(linter, checker_method, message_id_or_symbol, test_func): # pylint 2.0 renamed check_message_id to get_message_definition in: # https://github.com/PyCQA/pylint/commit/5ccbf9eaa54c0c302c9180bdfb745566c16e416d + # pylint 2.3.0 renamed get_message_definition to get_message_definitions in: + # https://github.com/PyCQA/pylint/commit/da67a9da682e51844fbc674229ff6619eb9c816a if hasattr(msgs_store, 'check_message_id'): - get_message_definition = msgs_store.check_message_id + get_message_definitions = msgs_store.check_message_id + elif hasattr(msgs_store, 'get_message_definition'): + get_message_definitions = msgs_store.get_message_definition else: - get_message_definition = msgs_store.get_message_definition + get_message_definitions = msgs_store.get_message_definitions try: - pylint_message = get_message_definition(message_id_or_symbol) + pylint_message = get_message_definitions(message_id_or_symbol) + pylint_message = pylint_message[0] if isinstance(pylint_message, (list, tuple)) else pylint_message symbols = [s for s in (pylint_message.msgid, pylint_message.symbol) if s is not None] except UnknownMessage: # This can happen due to mismatches of pylint versions and plugin expectations of available messages From 6d86209784941439245314e58b582df088b7e5ee Mon Sep 17 00:00:00 2001 From: Shepilov Vladislav Date: Wed, 27 Feb 2019 20:48:49 +0300 Subject: [PATCH 2/2] [FIX] Support MessagesStore.get_message_definitions interface. Thanks https://github.com/PyCQA/pylint-plugin-utils/pull/14 for more readable and better solution. --- pylint_plugin_utils/__init__.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/pylint_plugin_utils/__init__.py b/pylint_plugin_utils/__init__.py index c095ebb..a76bcf4 100644 --- a/pylint_plugin_utils/__init__.py +++ b/pylint_plugin_utils/__init__.py @@ -117,21 +117,26 @@ def suppress_message(linter, checker_method, message_id_or_symbol, test_func): # compatability with <=1.2 and >=1.3 msgs_store = getattr(linter, 'msgs_store', linter) - # pylint 2.0 renamed check_message_id to get_message_definition in: - # https://github.com/PyCQA/pylint/commit/5ccbf9eaa54c0c302c9180bdfb745566c16e416d - # pylint 2.3.0 renamed get_message_definition to get_message_definitions in: - # https://github.com/PyCQA/pylint/commit/da67a9da682e51844fbc674229ff6619eb9c816a - if hasattr(msgs_store, 'check_message_id'): - get_message_definitions = msgs_store.check_message_id - elif hasattr(msgs_store, 'get_message_definition'): - get_message_definitions = msgs_store.get_message_definition - else: - get_message_definitions = msgs_store.get_message_definitions + def get_message_definitions(message_id_or_symbol): + if hasattr(msgs_store, 'check_message_id'): + return [msgs_store.check_message_id(message_id_or_symbol)] + # pylint 2.0 renamed check_message_id to get_message_definition in: + # https://github.com/PyCQA/pylint/commit/5ccbf9eaa54c0c302c9180bdfb745566c16e416d + elif hasattr(msgs_store, 'get_message_definition'): + return [msgs_store.get_message_definition(message_id_or_symbol)] + # pylint 2.3.0 renamed get_message_definition to get_message_definitions in: + # https://github.com/PyCQA/pylint/commit/da67a9da682e51844fbc674229ff6619eb9c816a + elif hasattr(msgs_store, 'get_message_definitions'): + return msgs_store.get_message_definitions(message_id_or_symbol) + else: + raise ValueError('pylint.utils.MessagesStore does not have a get_message_definition(s) method') try: - pylint_message = get_message_definitions(message_id_or_symbol) - pylint_message = pylint_message[0] if isinstance(pylint_message, (list, tuple)) else pylint_message - symbols = [s for s in (pylint_message.msgid, pylint_message.symbol) if s is not None] + pylint_messages = get_message_definitions(message_id_or_symbol) + symbols = [symbol + for pylint_message in pylint_messages + for symbol in (pylint_message.msgid, pylint_message.symbol) + if symbol is not None] except UnknownMessage: # This can happen due to mismatches of pylint versions and plugin expectations of available messages symbols = [message_id_or_symbol]