Skip to content

Commit a542164

Browse files
authored
Do not use deprecated methods in PyLinter (#6293)
1 parent 4438029 commit a542164

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

pylint/lint/pylinter.py

-9
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,6 @@ def __init__(
670670
("RP0003", "Messages", report_messages_stats),
671671
)
672672
self.register_checker(self)
673-
with warnings.catch_warnings():
674-
warnings.filterwarnings("ignore", category=DeprecationWarning)
675-
self.load_provider_defaults()
676673

677674
def load_default_plugins(self):
678675
checkers.initialize(self)
@@ -810,14 +807,8 @@ def register_checker(self, checker: checkers.BaseChecker) -> None:
810807
self._checkers[checker.name].append(checker)
811808
for r_id, r_title, r_cb in checker.reports:
812809
self.register_report(r_id, r_title, r_cb, checker)
813-
with warnings.catch_warnings():
814-
warnings.filterwarnings("ignore", category=DeprecationWarning)
815-
self.register_options_provider(checker)
816810
if hasattr(checker, "msgs"):
817811
self.msgs_store.register_messages_from_checker(checker)
818-
with warnings.catch_warnings():
819-
warnings.filterwarnings("ignore", category=DeprecationWarning)
820-
checker.load_defaults()
821812
# Register the checker, but disable all of its messages.
822813
if not getattr(checker, "enabled", True):
823814
self.disable(checker.name)

tests/config/functional/toml/unknown_msgid/enable_unknown_msgid.result.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"functional_append": {
3-
"disable": ["logging-format-interpolation"],
43
"enable": ["locally-disabled"]
54
},
65
"functional_remove": {

tests/config/test_deprecations.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ class TestDeprecationArgumentsManager:
2424

2525
@classmethod
2626
def setup_class(cls) -> None:
27-
cls.linter.register_checker(SampleChecker(cls.linter))
27+
checker = SampleChecker(cls.linter)
28+
cls.linter.register_checker(checker)
29+
with pytest.warns(DeprecationWarning):
30+
cls.linter.register_options_provider(checker)
2831

2932
def test_load_configuration(self) -> None:
3033
"""Test that load_configuration emits a DeprecationWarning."""
@@ -48,3 +51,11 @@ def test_help_with_level(self) -> None:
4851
with warnings.catch_warnings():
4952
warnings.simplefilter("error")
5053
self.linter.help()
54+
55+
def test_register_options_provider_load_defaults(self) -> None:
56+
"""Test that register_options_provider and load_defaults emits a DeprecationWarning."""
57+
checker = BaseChecker(self.linter)
58+
with pytest.warns(DeprecationWarning):
59+
self.linter.register_options_provider(checker)
60+
with pytest.warns(DeprecationWarning):
61+
self.linter.load_defaults()

tests/test_import_graph.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,18 @@ def remove_files() -> Iterator:
8181
pass
8282

8383

84-
# pylint: disable-next=fixme
85-
# TODO: Fix these tests after all necessary options support the argparse framework
86-
@pytest.mark.xfail(reason="Not all options support argparse parsing")
8784
@pytest.mark.usefixtures("remove_files")
8885
def test_checker_dep_graphs(linter: PyLinter) -> None:
89-
linter.global_set_option("persistent", False)
90-
linter.global_set_option("reports", True)
91-
linter.global_set_option("enable", "imports")
92-
linter.global_set_option("import-graph", "import.dot")
93-
linter.global_set_option("ext-import-graph", "ext_import.dot")
94-
linter.global_set_option("int-import-graph", "int_import.dot")
95-
linter.global_set_option("int-import-graph", "int_import.dot")
86+
# pylint: disable-next=fixme
87+
# TODO: Optparse: Fix how these options are set
88+
linter.set_option("persistent", False)
89+
linter.set_option("reports", True)
90+
linter.set_option("enable", "imports")
91+
linter.namespace.import_graph = "import.dot"
92+
linter.namespace.ext_import_graph = "ext_import.dot"
93+
linter.namespace.int_import_graph = "int_import.dot"
9694
# ignore this file causing spurious MemoryError w/ some python version (>=2.3?)
97-
linter.global_set_option("ignore", ("func_unknown_encoding.py",))
95+
linter.set_option("ignore", ("func_unknown_encoding.py",))
9896
linter.check(["input"])
9997
linter.generate_reports()
10098
assert exists("import.dot")

0 commit comments

Comments
 (0)