Skip to content

Commit cf0c5e6

Browse files
committed
Pylint 1.4+ changed the add_message API, so here is a nasty hack to figure out which is being used.
1 parent 5d80ed6 commit cf0c5e6

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

pylint_plugin_utils/__init__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,26 @@ def __enter__(self):
6868
self._linter.add_message = self.add_message
6969
return self
7070

71-
def add_message(self, *args):
72-
self._messages_to_append.append(args)
71+
def add_message(self, *args, **kwargs):
72+
self._messages_to_append.append((args, kwargs))
7373

7474
def suppress(self, *symbols):
7575
for symbol in symbols:
7676
self._suppress.append(symbol)
7777

7878
def __exit__(self, exc_type, exc_val, exc_tb):
7979
self._linter.add_message = self._orig_add_message
80-
for to_append in self._messages_to_append:
81-
if to_append[0] in self._suppress:
80+
for to_append_args, to_append_kwargs in self._messages_to_append:
81+
# Depending on the Pylint version, the add_message API is different.
82+
# Either a single object called 'message' is passed, or the first argument
83+
# is a message symbol.
84+
if hasattr('symbol', to_append_args[0]):
85+
code = to_append_args[0].symbol
86+
else:
87+
code = to_append_args[0]
88+
if to_append_args[0] in self._suppress:
8289
continue
83-
self._linter.add_message(*to_append)
90+
self._linter.add_message(*to_append_args, **to_append_kwargs)
8491

8592

8693
def supress_message(linter, checker_method, message_id, test_func):

0 commit comments

Comments
 (0)