Skip to content

Do not use deprecated methods in PyLinter #6293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 13, 2022
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
9 changes: 0 additions & 9 deletions pylint/lint/pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,6 @@ def __init__(
("RP0003", "Messages", report_messages_stats),
)
self.register_checker(self)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
self.load_provider_defaults()

def load_default_plugins(self):
checkers.initialize(self)
Expand Down Expand Up @@ -810,14 +807,8 @@ def register_checker(self, checker: checkers.BaseChecker) -> None:
self._checkers[checker.name].append(checker)
for r_id, r_title, r_cb in checker.reports:
self.register_report(r_id, r_title, r_cb, checker)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
self.register_options_provider(checker)
if hasattr(checker, "msgs"):
self.msgs_store.register_messages_from_checker(checker)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
checker.load_defaults()
# Register the checker, but disable all of its messages.
if not getattr(checker, "enabled", True):
self.disable(checker.name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"functional_append": {
"disable": ["logging-format-interpolation"],
"enable": ["locally-disabled"]
},
"functional_remove": {
Expand Down
13 changes: 12 additions & 1 deletion tests/config/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class TestDeprecationArgumentsManager:

@classmethod
def setup_class(cls) -> None:
cls.linter.register_checker(SampleChecker(cls.linter))
checker = SampleChecker(cls.linter)
cls.linter.register_checker(checker)
with pytest.warns(DeprecationWarning):
cls.linter.register_options_provider(checker)

def test_load_configuration(self) -> None:
"""Test that load_configuration emits a DeprecationWarning."""
Expand All @@ -48,3 +51,11 @@ def test_help_with_level(self) -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")
self.linter.help()

def test_register_options_provider_load_defaults(self) -> None:
"""Test that register_options_provider and load_defaults emits a DeprecationWarning."""
checker = BaseChecker(self.linter)
with pytest.warns(DeprecationWarning):
self.linter.register_options_provider(checker)
with pytest.warns(DeprecationWarning):
self.linter.load_defaults()
20 changes: 9 additions & 11 deletions tests/test_import_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,18 @@ def remove_files() -> Iterator:
pass


# pylint: disable-next=fixme
# TODO: Fix these tests after all necessary options support the argparse framework
@pytest.mark.xfail(reason="Not all options support argparse parsing")
@pytest.mark.usefixtures("remove_files")
def test_checker_dep_graphs(linter: PyLinter) -> None:
linter.global_set_option("persistent", False)
linter.global_set_option("reports", True)
linter.global_set_option("enable", "imports")
linter.global_set_option("import-graph", "import.dot")
linter.global_set_option("ext-import-graph", "ext_import.dot")
linter.global_set_option("int-import-graph", "int_import.dot")
linter.global_set_option("int-import-graph", "int_import.dot")
# pylint: disable-next=fixme
# TODO: Optparse: Fix how these options are set
linter.set_option("persistent", False)
linter.set_option("reports", True)
linter.set_option("enable", "imports")
linter.namespace.import_graph = "import.dot"
linter.namespace.ext_import_graph = "ext_import.dot"
linter.namespace.int_import_graph = "int_import.dot"
# ignore this file causing spurious MemoryError w/ some python version (>=2.3?)
linter.global_set_option("ignore", ("func_unknown_encoding.py",))
linter.set_option("ignore", ("func_unknown_encoding.py",))
linter.check(["input"])
linter.generate_reports()
assert exists("import.dot")
Expand Down