diff options
-rw-r--r-- | pylint/config/argument.py | 14 | ||||
-rw-r--r-- | pylint/config/option.py | 7 | ||||
-rw-r--r-- | pylint/interfaces.py | 2 | ||||
-rw-r--r-- | pylint/lint/pylinter.py | 6 | ||||
-rw-r--r-- | pylintrc | 2 |
5 files changed, 25 insertions, 6 deletions
diff --git a/pylint/config/argument.py b/pylint/config/argument.py index 91abecc18..c64439ec7 100644 --- a/pylint/config/argument.py +++ b/pylint/config/argument.py @@ -13,6 +13,7 @@ import pathlib import re from typing import Callable, Dict, List, Optional, Pattern, Sequence, Tuple, Union +from pylint import interfaces from pylint import utils as pylint_utils _ArgumentTypes = Union[ @@ -28,6 +29,17 @@ _ArgumentTypes = Union[ """List of possible argument types.""" +def _confidence_transformer(value: str) -> Sequence[str]: + """Transforms a comma separated string of confidence values.""" + values = pylint_utils._check_csv(value) + for confidence in values: + if confidence not in interfaces.CONFIDENCE_LEVEL_NAMES: + raise argparse.ArgumentTypeError( + f"{value} should be in {*interfaces.CONFIDENCE_LEVEL_NAMES,}" + ) + return values + + def _csv_transformer(value: str) -> Sequence[str]: """Transforms a comma separated string.""" return pylint_utils._check_csv(value) @@ -94,7 +106,7 @@ _TYPE_TRANSFORMERS: Dict[str, Callable[[str], _ArgumentTypes]] = { "csv": _csv_transformer, "float": float, "int": int, - "multiple_choice": _csv_transformer, + "confidence": _confidence_transformer, "non_empty_string": _non_empty_string_transformer, "py_version": _py_version_transformer, "regexp": re.compile, diff --git a/pylint/config/option.py b/pylint/config/option.py index 260e0a220..ab24b2302 100644 --- a/pylint/config/option.py +++ b/pylint/config/option.py @@ -106,6 +106,9 @@ VALIDATORS = { "csv": _csv_validator, "yn": _yn_validator, "choice": lambda opt, name, value: _choice_validator(opt["choices"], name, value), + "confidence": lambda opt, name, value: _multiple_choice_validator( + opt["choices"], name, value + ), "multiple_choice": lambda opt, name, value: _multiple_choice_validator( opt["choices"], name, value ), @@ -148,6 +151,7 @@ class Option(optparse.Option): "regexp_paths_csv", "csv", "yn", + "confidence", "multiple_choice", "non_empty_string", "py_version", @@ -159,6 +163,7 @@ class Option(optparse.Option): TYPE_CHECKER["regexp_paths_csv"] = _regexp_paths_csv_validator TYPE_CHECKER["csv"] = _csv_validator TYPE_CHECKER["yn"] = _yn_validator + TYPE_CHECKER["confidence"] = _multiple_choices_validating_option TYPE_CHECKER["multiple_choice"] = _multiple_choices_validating_option TYPE_CHECKER["non_empty_string"] = _non_empty_string_validator TYPE_CHECKER["py_version"] = _py_version_validator @@ -169,7 +174,7 @@ class Option(optparse.Option): self.help = optparse.SUPPRESS_HELP def _check_choice(self): - if self.type in {"choice", "multiple_choice"}: + if self.type in {"choice", "multiple_choice", "confidence"}: if self.choices is None: raise optparse.OptionError( "must supply a list of choices for type 'choice'", self diff --git a/pylint/interfaces.py b/pylint/interfaces.py index 7f6edbdf5..661525bac 100644 --- a/pylint/interfaces.py +++ b/pylint/interfaces.py @@ -24,6 +24,7 @@ __all__ = ( "INFERENCE_FAILURE", "UNDEFINED", "CONFIDENCE_LEVELS", + "CONFIDENCE_LEVEL_NAMES", ) Confidence = namedtuple("Confidence", ["name", "description"]) @@ -39,6 +40,7 @@ INFERENCE_FAILURE = Confidence( UNDEFINED = Confidence("UNDEFINED", "Warning without any associated confidence level.") CONFIDENCE_LEVELS = [HIGH, CONTROL_FLOW, INFERENCE, INFERENCE_FAILURE, UNDEFINED] +CONFIDENCE_LEVEL_NAMES = [i.name for i in CONFIDENCE_LEVELS] class Interface: diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py index 788ce4f12..18db827b1 100644 --- a/pylint/lint/pylinter.py +++ b/pylint/lint/pylinter.py @@ -355,10 +355,10 @@ class PyLinter( ( "confidence", { - "type": "multiple_choice", + "type": "confidence", "metavar": "<levels>", - "default": "", - "choices": [c.name for c in interfaces.CONFIDENCE_LEVELS], + "default": interfaces.CONFIDENCE_LEVEL_NAMES, + "choices": interfaces.CONFIDENCE_LEVEL_NAMES, "group": "Messages control", "help": "Only show warnings with the listed confidence levels." f" Leave empty to show all. Valid levels: {', '.join(c.name for c in interfaces.CONFIDENCE_LEVELS)}.", @@ -74,7 +74,7 @@ fail-on= # Only show warnings with the listed confidence levels. Leave empty to show # all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED -confidence= +# confidence= # 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 |