diff --git a/pylint/config/arguments_manager.py b/pylint/config/arguments_manager.py index 08c8a46c54..21d60b2ec0 100644 --- a/pylint/config/arguments_manager.py +++ b/pylint/config/arguments_manager.py @@ -14,7 +14,7 @@ import sys import warnings from pathlib import Path -from typing import TYPE_CHECKING, Dict, List, Optional, TextIO, Tuple, Union +from typing import TYPE_CHECKING, Any, Dict, List, Optional, TextIO, Tuple, Union from pylint import utils from pylint.config.argument import ( @@ -517,15 +517,14 @@ def _parse_toml(self, config_file: Path, parser: configparser.ConfigParser) -> N parser.add_section(section_name) parser.set(section_name, option, value=value) - # pylint: disable-next=fixme - # TODO: Optparse: All methods below this line are copied to keep API-parity with - # OptionsManagerMixIn. They should either be deprecated or moved above this line - # to keep them in _ArgumentsManager - - def load_config_file(self): + def load_config_file(self) -> None: """Dispatch values previously read from a configuration file to each option's provider """ + warnings.warn( + "load_config_file has been deprecated. It will be removed in pylint 3.0.", + DeprecationWarning, + ) parser = self.cfgfile_parser for section in parser.sections(): for option, value in parser.items(section): @@ -534,16 +533,31 @@ def load_config_file(self): except (KeyError, optparse.OptionError): continue - def load_configuration(self, **kwargs): + def load_configuration(self, **kwargs: Any) -> None: """Override configuration according to given parameters.""" - return self.load_configuration_from_config(kwargs) + warnings.warn( + "load_configuration has been deprecated. It will be removed in pylint 3.0.", + DeprecationWarning, + ) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=DeprecationWarning) + return self.load_configuration_from_config(kwargs) - def load_configuration_from_config(self, config): + def load_configuration_from_config(self, config: Dict[str, Any]) -> None: + warnings.warn( + "load_configuration_from_config has been deprecated. It will be removed in pylint 3.0.", + DeprecationWarning, + ) for opt, opt_value in config.items(): opt = opt.replace("_", "-") provider = self._all_options[opt] provider.set_option(opt, opt_value) + # pylint: disable-next=fixme + # TODO: Optparse: All methods below this line are copied to keep API-parity with + # OptionsManagerMixIn. They should either be deprecated or moved above this line + # to keep them in _ArgumentsManager + def load_command_line_configuration(self, args=None) -> List[str]: """Override configuration according to command line parameters. diff --git a/pylint/config/config_initialization.py b/pylint/config/config_initialization.py index d8cf06e9c5..58537f46df 100644 --- a/pylint/config/config_initialization.py +++ b/pylint/config/config_initialization.py @@ -63,7 +63,9 @@ def _config_initialization( # Now we can load file config, plugins (which can # provide options) have been registered - linter.load_config_file() + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=DeprecationWarning) + linter.load_config_file() try: linter.load_command_line_configuration(args_list) diff --git a/tests/config/test_deprecations.py b/tests/config/test_deprecations.py new file mode 100644 index 0000000000..eaca14044d --- /dev/null +++ b/tests/config/test_deprecations.py @@ -0,0 +1,36 @@ +# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html +# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt + +"""Test for deprecation warnings in the config module.""" + + +import pytest + +from pylint.checkers import BaseChecker +from pylint.lint import PyLinter + + +class SampleChecker(BaseChecker): + options = (("test-opt", {"action": "store_true"}),) + + +class TestDeprecationArgumentsManager: + """Tests for deprecation warnings in the ArgumentsManager class.""" + + linter = PyLinter() + + @classmethod + def setup_class(cls) -> None: + cls.linter.register_checker(SampleChecker(cls.linter)) + + def test_load_configuration(self) -> None: + """Test that load_configuration emits a DeprecationWarning.""" + + with pytest.warns(DeprecationWarning): + self.linter.load_configuration(test_opt=True) + + def test_load_configuration_from_config(self) -> None: + """Test that load_configuration_from_config emits a DeprecationWarning.""" + with pytest.warns(DeprecationWarning): + self.linter.load_configuration_from_config({"test_opt": True})