From 43133c56d47bbc60e51a7f40433116b826eb18b7 Mon Sep 17 00:00:00 2001 From: Matus Valo Date: Sat, 1 May 2021 20:00:26 +0200 Subject: [PATCH] Add support for checking deprecated class arguments. (#4425) * Add deprecated class arguments --- pylint/checkers/deprecated.py | 1 + pylint/checkers/stdlib.py | 2 ++ tests/checkers/unittest_deprecated.py | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/pylint/checkers/deprecated.py b/pylint/checkers/deprecated.py index 38ba5d546..3279951cd 100644 --- a/pylint/checkers/deprecated.py +++ b/pylint/checkers/deprecated.py @@ -13,6 +13,7 @@ ACCEPTABLE_NODES = ( astroid.BoundMethod, astroid.UnboundMethod, astroid.FunctionDef, + astroid.ClassDef, ) diff --git a/pylint/checkers/stdlib.py b/pylint/checkers/stdlib.py index 7b60a9a10..44fb071ee 100644 --- a/pylint/checkers/stdlib.py +++ b/pylint/checkers/stdlib.py @@ -63,6 +63,8 @@ DEPRECATED_ARGUMENTS = { "asyncio.subprocess.create_subprocess_shell": ((4, "loop"),), "gettext.translation": ((5, "codeset"),), "gettext.install": ((2, "codeset"),), + "functools.partialmethod": ((None, "func"),), + "weakref.finalize": ((None, "func"), (None, "obj")), "profile.Profile.runcall": ((None, "func"),), "cProfile.Profile.runcall": ((None, "func"),), "bdb.Bdb.runcall": ((None, "func"),), diff --git a/tests/checkers/unittest_deprecated.py b/tests/checkers/unittest_deprecated.py index f9b45cd6d..a15596abc 100644 --- a/tests/checkers/unittest_deprecated.py +++ b/tests/checkers/unittest_deprecated.py @@ -34,6 +34,9 @@ class _DeprecatedChecker(DeprecatedMixin, BaseChecker): if method == ".MyClass.mymethod3": # def mymethod1(self, arg1, *, deprecated_arg1=None) return ((None, "deprecated_arg1"),) + if method == ".MyClass": + # def __init__(self, deprecated_arg=None) + return ((0, "deprecated_arg"),) return () @@ -359,6 +362,27 @@ class TestDeprecatedChecker(CheckerTestCase): ): self.checker.visit_call(node) + def test_class_deprecated_arguments(self): + + node = astroid.extract_node( + """ + class MyClass: + def __init__(self, deprecated_arg=None): + pass + + MyClass(5) + """ + ) + with self.assertAddsMessages( + Message( + msg_id="deprecated-argument", + args=("deprecated_arg", "MyClass"), + node=node, + confidence=UNDEFINED, + ) + ): + self.checker.visit_call(node) + def test_deprecated_module(self): # Tests detecting deprecated module node = astroid.extract_node(