Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ contributors:

* Pierre Sassoulas : contributor
- Made C0412 (ungrouped import) compatible with isort
- Made multiple message with the same old name possible
- Made Pylint a little faster by refactoring the message store

* Nathan Marrow

Expand Down
2 changes: 1 addition & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ Release date: TBA
* Allow a `.` as a prefix for Sphinx name resolution.

* Checkers must now keep a 1 to 1 relationship between "msgid" (ie: C1234) and "symbol" (ie : human-readable-symbol)
* In checkers, an old_names can now be used for multiple new messages
* In checkers, an old_names can now be used for multiple new messages and pylint is now a little faster

Caused by #1164. It means if you do a partial old_names for a message definition an exception will tell you that you
must rename the associated identification.
Expand Down
19 changes: 4 additions & 15 deletions pylint/message/message_definition_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ def __init__(self):
# It contains the 1:1 mapping from msgid to MessageDefinition.
# Keys are msgid, values are MessageDefinition
self._messages_definitions = {}
# Secondary registry for all old names kept for compatibility reasons
# May contain identical values under different MessageId
# (ie a MessageDefinition was renamed more than once)
self._old_message_definitions = {}
# MessageDefinition kept by category
self._msgs_by_category = collections.defaultdict(list)

Expand All @@ -51,9 +47,6 @@ def register_message(self, message):
"""
self.message_id_store.register_message_definition(message)
self._messages_definitions[message.msgid] = message
self._old_message_definitions[message.msgid] = message
for old_msgid, _ in message.old_names:
self._old_message_definitions[old_msgid] = message
self._msgs_by_category[message.msgid[0]].append(message.msgid)

def get_message_definitions(self, msgid_or_symbol: str) -> list:
Expand All @@ -63,14 +56,10 @@ def get_message_definitions(self, msgid_or_symbol: str) -> list:
:rtype: List of MessageDefinition
:return: A message definition corresponding to msgid_or_symbol
"""
message_definitions = []
message_ids = self.message_id_store.get_active_msgids(msgid_or_symbol)
for message_id in message_ids:
message_definition = self._messages_definitions.get(message_id)
if message_definition is None:
message_definition = self._old_message_definitions.get(message_id)
message_definitions.append(message_definition)
return message_definitions
return [
self._messages_definitions[m]
for m in self.message_id_store.get_active_msgids(msgid_or_symbol)
]

def get_msg_display_string(self, msgid_or_symbol: str):
"""Generates a user-consumable representation of a message. """
Expand Down
3 changes: 1 addition & 2 deletions pylint/message/message_handler_mix_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ def _set_msg_status(
if msgid.lower() in self._checkers:
for checker in self._checkers[msgid.lower()]:
for _msgid in checker.msgs:
if _msgid in self.msgs_store._old_message_definitions:
self._set_msg_status(_msgid, enable, scope, line)
self._set_msg_status(_msgid, enable, scope, line)
return

# msgid is report id?
Expand Down
7 changes: 6 additions & 1 deletion pylint/message/message_id_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,9 @@ def get_active_msgids(self, msgid_or_symbol: str) -> List[str]:
msgid_or_symbol=msgid_or_symbol
)
raise UnknownMessageError(error_msg)
return [msgid]
# logging.debug(
# "Return for {} and msgid {} is {}".format(
# msgid_or_symbol, msgid, self.__old_names.get(msgid, [msgid])
# )
# )
return self.__old_names.get(msgid, [msgid])
33 changes: 33 additions & 0 deletions tests/message/unittest_message_definition_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,36 @@ def test_list_messages(self, store):
def test_renamed_message_register(self, store):
assert "msg-symbol" == store.get_message_definitions("W0001")[0].symbol
assert "msg-symbol" == store.get_message_definitions("old-symbol")[0].symbol


def test_multiple_child_of_old_name(store):
""" We can define multiple name with the same old name. """

class FamillyChecker(BaseChecker):
name = "famillychecker"
msgs = {
"W1235": (
"Child 1",
"child-one",
"Child one description.",
{"old_names": [("C1234", "mother")]},
),
"W1236": (
"Child 2",
"child-two",
"Child two description",
{"old_names": [("C1234", "mother")]},
),
}

store.register_messages_from_checker(FamillyChecker())
mother = store.get_message_definitions("C1234")
child = store.get_message_definitions("W1235")
other_child = store.get_message_definitions("W1236")
assert len(mother) == 2
assert len(child) == 1
assert len(other_child) == 1
child = child[0]
other_child = other_child[0]
assert child in mother
assert other_child in mother
20 changes: 20 additions & 0 deletions tests/message/unittest_message_id_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@ def test_register_message_definitions(empty_msgid_store, message_definitions):
assert len(empty_msgid_store) == number_of_msgid


def test_add_msgid_and_symbol(empty_msgid_store):
empty_msgid_store.add_msgid_and_symbol("E1235", "new-sckiil")
empty_msgid_store.add_legacy_msgid_and_symbol("C1235", "old-sckiil", "E1235")
assert len(empty_msgid_store) == 2
message_ids = empty_msgid_store.get_active_msgids("E1235")
assert len(message_ids) == 1
assert message_ids[0] == "E1235"
message_ids = empty_msgid_store.get_active_msgids("old-sckiil")
assert len(message_ids) == 1
assert message_ids[0] == "E1235"
assert empty_msgid_store.get_symbol("C1235") == "old-sckiil"
assert empty_msgid_store.get_symbol("E1235") == "new-sckiil"
assert empty_msgid_store.get_msgid("old-sckiil") == "C1235"
assert empty_msgid_store.get_msgid("new-sckiil") == "E1235"
with pytest.raises(KeyError) as e:
empty_msgid_store.get_symbol("C1234")
with pytest.raises(KeyError) as e:
empty_msgid_store.get_msgid("not-exist")


def test_duplicate_symbol(empty_msgid_store):
empty_msgid_store.add_msgid_and_symbol("W1234", "warning-symbol")
with pytest.raises(InvalidMessageError) as error:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def _split_lines(self, expected_messages, lines):
def _check_output_text(self, expected_messages, expected_lines, received_lines):
assert (
self._split_lines(expected_messages, expected_lines)[0] == received_lines
), self._test_file.base
), "Error with the following functional test: {}".format(self._test_file.base)


class LintModuleOutputUpdate(LintModuleTest):
Expand Down