Skip to content

Commit 0009c94

Browse files
committed
At some point that I have not been able track down exactly, pylint started emitting symbols rather than message IDs by default, which broke message supression which relied on the IDs only. This has now been fixed to ignore based on both the message ID and the symbol.
1 parent 496a968 commit 0009c94

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

pylint_plugin_utils/__init__.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import sys
2+
from pylint.utils import UnknownMessage
3+
24

35
def get_class(module_name, kls):
46
parts = kls.split('.')
@@ -69,8 +71,9 @@ def __enter__(self):
6971
def add_message(self, *args):
7072
self._messages_to_append.append(args)
7173

72-
def suppress(self, msg_id):
73-
self._suppress.append(msg_id)
74+
def suppress(self, *symbols):
75+
for symbol in symbols:
76+
self._suppress.append(symbol)
7477

7578
def __exit__(self, exc_type, exc_val, exc_tb):
7679
self._linter.add_message = self._orig_add_message
@@ -87,15 +90,25 @@ def supress_message(linter, checker_method, message_id, test_func):
8790
return suppress_message(linter, checker_method, message_id, test_func)
8891

8992

90-
def suppress_message(linter, checker_method, message_id, test_func):
93+
def suppress_message(linter, checker_method, message_id_or_symbol, test_func):
9194
"""
9295
This wrapper allows the suppression of a message if the supplied test function
9396
returns True. It is useful to prevent one particular message from being raised
9497
in one particular case, while leaving the rest of the messages intact.
9598
"""
99+
# At some point, pylint started preferring message symbols to message IDs. However this is not done
100+
# consistently or uniformly. We try to work around this here by suppressing both the ID and the symbol,
101+
# if we can find it.
102+
try:
103+
pylint_message = linter.check_message_id(message_id_or_symbol)
104+
symbols = [s for s in (pylint_message.msgid, pylint_message.symbol) if s is not None]
105+
except UnknownMessage:
106+
# This can happen due to mismatches of pylint versions and plugin expectations of available messages
107+
symbols = [message_id_or_symbol]
108+
96109
def do_suppress(chain, node):
97110
with Suppress(linter) as s:
98111
if test_func(node):
99-
s.suppress(message_id)
112+
s.suppress(*symbols)
100113
chain()
101114
augment_visit(linter, checker_method, do_suppress)

0 commit comments

Comments
 (0)