Skip to content
Merged
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
34 changes: 24 additions & 10 deletions pylint/config/arguments_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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):
Expand All @@ -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.

Expand Down
4 changes: 3 additions & 1 deletion pylint/config/config_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 36 additions & 0 deletions tests/config/test_deprecations.py
Original file line number Diff line number Diff line change
@@ -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})