Skip to content
Draft
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: 1 addition & 1 deletion doc/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ hint of what Pylint is going to ``pick on``: ::
further processing.

When Pylint is first run on a fresh piece of code, a common complaint is that it
is too ``noisy``. The default configuration enforce a lot of warnings.
is too ``noisy``. The default configuration enforces a lot of warnings.
We'll use some of the options we noted above to make it suit your
preferences a bit better.

Expand Down
3 changes: 3 additions & 0 deletions pylint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

__all__ = [
"__version__",
"core",
"modify_sys_path",
"recommended",
"run_pylint",
"run_pyreverse",
"run_symilar",
Expand All @@ -19,6 +21,7 @@
from typing import NoReturn

from pylint.__pkginfo__ import __version__
from pylint.message_sets import core, recommended

# pylint: disable=import-outside-toplevel

Expand Down
2 changes: 2 additions & 0 deletions pylint/config/arguments_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ def _generate_config(
"""Write a configuration file according to the current configuration
into the given stream or stdout.
"""
# If --message-sets is absent, maybe just go ahead and
# set --message-sets=pylint.recommended? or wait until pylint 5?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I trust that what we can devise now is still better than the current default. (But we can wait for 5 too)

options_by_section = {}
sections = []
for group in sorted(
Expand Down
18 changes: 18 additions & 0 deletions pylint/config/callback_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,24 @@ def __call__(
raise NotImplementedError # pragma: no cover


class _MessageSetsAction(_AccessLinterObjectAction):
"""Callback action for setting message sets."""

def __call__(
self,
parser: argparse.ArgumentParser,
namespace: argparse.Namespace,
values: str | Sequence[Any] | None,
option_string: str | None = "--disable",
) -> None:
for msg_set in values or ():
actions = utils.utils._import_attribute(msg_set)
for enable in actions["enable"]:
self.linter.enable(enable)
for disable in actions["disable"]:
self.linter.disable(disable)


class _DisableAction(_XableAction):
"""Callback action for disabling a message."""

Expand Down
14 changes: 14 additions & 0 deletions pylint/lint/base_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
_ListMessagesEnabledAction,
_LongHelpAction,
_MessageHelpAction,
_MessageSetsAction,
_OutputFormatAction,
)
from pylint.typing import Options
Expand Down Expand Up @@ -181,6 +182,19 @@ def _make_linter_options(linter: PyLinter) -> Options:
f" Leave empty to show all. Valid levels: {', '.join(interfaces.CONFIDENCE_LEVEL_NAMES)}.",
},
),
(
"message-sets",
{
"action": _MessageSetsAction,
"callback": lambda x1, x2, x3, x4: x1,
"default": ("pylint.core"), # pylint.recommended in v5
"metavar": "<msg ids>",
"short": "msg-sets",
"group": "Messages control",
"help": "",
"kwargs": {"linter": linter},
},
),
(
"enable",
{
Expand Down
16 changes: 16 additions & 0 deletions pylint/message_sets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt

core: dict[str, set[str]] = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love the word "core", I was just trying to avoid "all" which could be confusing as it doesn't entail --enable-all-extensions nor the messages "disabled by default" with the checker setting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legacy for 'core' (i.e. pylint prior to pylint 4.0), 'recommended' (current default), extension / all (extension all and enable / all) ? We could add 'google', 'error' ('--error-only'), 'high-confidence' (no inference) and mozzila (although contrary to google I'm not sure there is a conveniant public pylintrc)

"enable": set(),
"disable": set(),
}

recommended: dict[str, set[str]] = {
"enable": set(),
"disable": {
"duplicate-code",
# add others from issue...
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixme, etc.

},
}
13 changes: 13 additions & 0 deletions pylint/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import warnings
from collections import deque
from collections.abc import Iterable, Sequence
from importlib import import_module
from io import BufferedReader, BytesIO
from re import Pattern
from typing import TYPE_CHECKING, Any, Literal, TextIO, TypeVar
Expand Down Expand Up @@ -264,6 +265,18 @@ def _check_regexp_csv(value: list[str] | tuple[str] | str) -> Iterable[str]:
yield from ("".join(regexp).strip() for regexp in regexps if regexp is not None)


def _import_attribute(dotted_path: str) -> Any:
try:
module_path, attribute_name = dotted_path.rsplit(".", 1)
except ValueError as err:
raise ImportError(f"{dotted_path} doesn't look like a module path") from err

if not (module := sys.modules.get(module_path)):
module = import_module(module_path)

return getattr(module, attribute_name)


def _comment(string: str) -> str:
"""Return string as a comment."""
lines = [line.strip() for line in string.splitlines()]
Expand Down
2 changes: 2 additions & 0 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ clear-cache-post-run=no
# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED
# confidence=

message-sets=pylint.recommended
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the name 'message sets' a lot. Maybe it's because I'd want to put everything inside this (option, message, extension, ... Except things like '--rc-file' or '--version', which will force us to think about it), so I would call it 'style' instead


# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
Expand Down
Loading