From 01676aea6042da07bf52a35b5bf82cc55865d13a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Wed, 13 Apr 2022 14:30:19 +0200 Subject: [PATCH] Remove use of deprecated methods in ``_ArgumentsProvider`` and ``_config_initialization`` --- pylint/config/arguments_provider.py | 3 --- pylint/config/config_initialization.py | 32 -------------------------- tests/config/test_deprecations.py | 15 ++++++++++++ 3 files changed, 15 insertions(+), 35 deletions(-) diff --git a/pylint/config/arguments_provider.py b/pylint/config/arguments_provider.py index 25d667eb29..3a850e3d1d 100644 --- a/pylint/config/arguments_provider.py +++ b/pylint/config/arguments_provider.py @@ -41,9 +41,6 @@ def __init__(self, arguments_manager: _ArgumentsManager) -> None: # TODO: Optparse: Added to keep API parity with OptionsProvider # They should be removed/deprecated when refactoring the copied methods self._config = optparse.Values() - with warnings.catch_warnings(): - warnings.filterwarnings("ignore", category=DeprecationWarning) - self.load_defaults() self.level = 0 @property diff --git a/pylint/config/config_initialization.py b/pylint/config/config_initialization.py index 9230ced42c..cd4457fb6a 100644 --- a/pylint/config/config_initialization.py +++ b/pylint/config/config_initialization.py @@ -3,7 +3,6 @@ # Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt import sys -import warnings from pathlib import Path from typing import TYPE_CHECKING, List, Union @@ -48,37 +47,6 @@ def _config_initialization( if "load-plugins" in config_data: linter.load_plugin_modules(utils._splitstrip(config_data["load-plugins"])) - # pylint: disable-next=fixme - # TODO: Remove everything until set_reporter once the optparse - # implementation is no longer needed - # Load optparse command line arguments - try: - # The parser is stored on linter.cfgfile_parser - with warnings.catch_warnings(): - warnings.filterwarnings("ignore", category=DeprecationWarning) - linter.read_config_file(config_file=config_file, verbose=verbose_mode) - except OSError as ex: - print(ex, file=sys.stderr) - sys.exit(32) - - # Now we can load file config, plugins (which can - # provide options) have been registered - with warnings.catch_warnings(): - warnings.filterwarnings("ignore", category=DeprecationWarning) - linter.load_config_file() - - # pylint: disable-next=fixme - # TODO: Optparse: This has been disabled pre-maturely because it interferes with - # argparse option parsing for 'disable' and 'enable'. - # try: - # with warnings.catch_warnings(): - # warnings.filterwarnings("ignore", category=DeprecationWarning) - # linter.load_command_line_configuration(args_list) - # except SystemExit as exc: - # if exc.code == 2: # bad options - # exc.code = 32 - # raise - # First we parse any options from a configuration file linter._parse_configuration_file(config_args) diff --git a/tests/config/test_deprecations.py b/tests/config/test_deprecations.py index 585d40d1eb..71e4deddeb 100644 --- a/tests/config/test_deprecations.py +++ b/tests/config/test_deprecations.py @@ -59,3 +59,18 @@ def test_register_options_provider_load_defaults(self) -> None: self.linter.register_options_provider(checker) with pytest.warns(DeprecationWarning): self.linter.load_defaults() + + def test_read_config_file(self) -> None: + """Test that read_config_file emits a DeprecationWarning.""" + with pytest.warns(DeprecationWarning): + self.linter.read_config_file() + + def test_load_config_file(self) -> None: + """Test that load_config_file emits a DeprecationWarning.""" + with pytest.warns(DeprecationWarning): + self.linter.load_config_file() + + def test_load_command_line_configuration(self) -> None: + """Test that load_command_line_configuration emits a DeprecationWarning.""" + with pytest.warns(DeprecationWarning): + self.linter.load_command_line_configuration([])