Skip to content

Commit

Permalink
Refactor --list-msgs & --list-msgs-enabled
Browse files Browse the repository at this point in the history
Both options now show which messages can't be emitted with the
current interpreter. This makes function more like their name implies.
This closes pylint-dev#4778
  • Loading branch information
DanielNoord committed Aug 3, 2021
1 parent 85b69c9 commit ecd0ef3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -75,6 +75,10 @@ Release date: TBA
Closes #3608
Closes #4346

* Refactor of ``--list-msgs`` & ``--list-msgs-enabled``: both options now show whether messages are emittable with the current interpreter.

Closes #4778


What's New in Pylint 2.9.6?
===========================
Expand Down
4 changes: 4 additions & 0 deletions doc/whatsnew/2.10.rst
Expand Up @@ -61,3 +61,7 @@ Other Changes
Closes #3249
Closes #3608
Closes #4346

* Refactor of ``--list-msgs`` & ``--list-msgs-enabled``: both options now show whether messages are emittable with the current interpreter.

Closes #4778
23 changes: 13 additions & 10 deletions pylint/lint/pylinter.py
Expand Up @@ -775,22 +775,25 @@ def python3_porting_mode(self):
self._python3_porting_mode = True

def list_messages_enabled(self):
enabled = [
f" {message.symbol} ({message.msgid})"
for message in self.msgs_store.messages
if self.is_message_enabled(message.msgid)
]
disabled = [
f" {message.symbol} ({message.msgid})"
for message in self.msgs_store.messages
if not self.is_message_enabled(message.msgid)
]
enabled = []
disabled = []
non_emittable = []
for message in self.msgs_store.messages:
if not message.may_be_emitted():
non_emittable.append(f" {message.symbol} ({message.msgid})")
elif self.is_message_enabled(message.msgid):
enabled.append(f" {message.symbol} ({message.msgid})")
else:
disabled.append(f" {message.symbol} ({message.msgid})")
print("Enabled messages:")
for msg in sorted(enabled):
print(msg)
print("\nDisabled messages:")
for msg in sorted(disabled):
print(msg)
print("\nNon-emittable messages with current interpreter:")
for msg in sorted(non_emittable):
print(msg)
print("")

# block level option handling #############################################
Expand Down
7 changes: 4 additions & 3 deletions pylint/lint/run.py
Expand Up @@ -156,7 +156,8 @@ def __init__(
"callback": self.cb_list_messages,
"group": "Commands",
"level": 1,
"help": "Generate pylint's messages.",
"help": "Display a list of all pylint's messages divided by whether "
"they are emittable with the given interpreter.",
},
),
(
Expand All @@ -167,8 +168,8 @@ def __init__(
"callback": self.cb_list_messages_enabled,
"group": "Commands",
"level": 1,
"help": "Display a list of what messages are enabled "
"and disabled with the given configuration.",
"help": "Display a list of what messages are enabled, "
"disabled and non-emittable with the given configuration.",
},
),
(
Expand Down
15 changes: 12 additions & 3 deletions pylint/message/message_definition_store.py
Expand Up @@ -74,8 +74,17 @@ def help_message(self, msgids_or_symbols: List[str]) -> None:
def list_messages(self) -> None:
"""Output full messages list documentation in ReST format."""
messages = sorted(self._messages_definitions.values(), key=lambda m: m.msgid)
emittable = []
non_emittable = []
for message in messages:
if not message.may_be_emitted():
continue
print(message.format_help(checkerref=False))
if message.may_be_emitted():
emittable.append(message.format_help(checkerref=False))
else:
non_emittable.append(message.format_help(checkerref=False))
print("Emittable messages with current interpreter:")
for msg in emittable:
print(msg)
print("\nNon-emittable messages with current interpreter:")
for msg in non_emittable:
print(msg)
print("")

0 comments on commit ecd0ef3

Please sign in to comment.