Add support for checking deprecated class arguments. (#4425)

* Add deprecated class arguments
This commit is contained in:
Matus Valo 2021-05-01 20:00:26 +02:00 committed by GitHub
parent 25ab48a347
commit 43133c56d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View File

@ -13,6 +13,7 @@ ACCEPTABLE_NODES = (
astroid.BoundMethod,
astroid.UnboundMethod,
astroid.FunctionDef,
astroid.ClassDef,
)

View File

@ -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"),),

View File

@ -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(