mirror of
https://fuchsia.googlesource.com/third_party/github.com/pylint-dev/pylint
synced 2024-09-22 00:24:37 +00:00
Add support for checking deprecated class arguments. (#4425)
* Add deprecated class arguments
This commit is contained in:
parent
25ab48a347
commit
43133c56d4
|
@ -13,6 +13,7 @@ ACCEPTABLE_NODES = (
|
|||
astroid.BoundMethod,
|
||||
astroid.UnboundMethod,
|
||||
astroid.FunctionDef,
|
||||
astroid.ClassDef,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -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"),),
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue
Block a user